From 464dbccb7bb8efefed63acf5ae131f60922dcd45 Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Mon, 2 Mar 2015 12:48:02 +0900 Subject: [PATCH] ompi/bcol: fix misc memory leaks as reported by Coverity with CIDs 715758-715762,715765 and 715767 --- ompi/mca/bcol/base/bcol_base_frame.c | 9 +++++++-- ompi/mca/bcol/basesmuma/bcol_basesmuma_buf_mgmt.c | 14 +++++++++++--- ompi/mca/bcol/basesmuma/bcol_basesmuma_module.c | 3 ++- ompi/mca/bcol/basesmuma/bcol_basesmuma_smcm.c | 4 +++- ompi/mca/bcol/ptpcoll/bcol_ptpcoll_module.c | 3 ++- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ompi/mca/bcol/base/bcol_base_frame.c b/ompi/mca/bcol/base/bcol_base_frame.c index 98b977367a..8ffa08a449 100644 --- a/ompi/mca/bcol/base/bcol_base_frame.c +++ b/ompi/mca/bcol/base/bcol_base_frame.c @@ -5,7 +5,7 @@ * Copyright (c) 2013 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2013-2014 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -159,6 +159,7 @@ static int mca_bcol_base_set_components_to_use(opal_list_t *bcol_components_avai /* found selected component */ b_clj = OBJ_NEW(mca_base_component_list_item_t); if (NULL == b_clj) { + opal_argv_free (bcols_requested); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -285,9 +286,13 @@ int mca_bcol_base_set_attributes(struct mca_bcol_base_module_t *bcol_module, int coll_type; comm_attribs = malloc(sizeof(mca_bcol_base_coll_fn_comm_attributes_t)); + if (NULL == comm_attribs) { + return OMPI_ERR_OUT_OF_RESOURCE; + } inv_attribs = malloc(sizeof(mca_bcol_base_coll_fn_invoke_attributes_t)); - if (!((comm_attribs) && (inv_attribs))) { + if (NULL == inv_attribs) { + free(comm_attribs); return OMPI_ERR_OUT_OF_RESOURCE; } diff --git a/ompi/mca/bcol/basesmuma/bcol_basesmuma_buf_mgmt.c b/ompi/mca/bcol/basesmuma/bcol_basesmuma_buf_mgmt.c index 79ca1e340f..1a65b5cb01 100644 --- a/ompi/mca/bcol/basesmuma/bcol_basesmuma_buf_mgmt.c +++ b/ompi/mca/bcol/basesmuma/bcol_basesmuma_buf_mgmt.c @@ -4,8 +4,8 @@ * Copyright (c) 2009-2012 Mellanox Technologies. All rights reserved. * Copyright (c) 2013-2014 Los Alamos National Security, LLC. * All rights reserved. - * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014-2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -265,7 +265,7 @@ int bcol_basesmuma_bank_init_opti(struct mca_bcol_base_memory_block_desc_t *payl (mca_bcol_basesmuma_module_t *)bcol_module; int my_idx, array_id; mca_bcol_basesmuma_header_t *ctl_ptr; - void **results_array, *mem_offset; + void **results_array=NULL, *mem_offset; mca_bcol_basesmuma_local_mlmem_desc_t *ml_mem = &sm_bcol_module->ml_mem; @@ -289,6 +289,10 @@ int bcol_basesmuma_bank_init_opti(struct mca_bcol_base_memory_block_desc_t *payl /* allocate some memory to hold the offsets */ results_array = (void **) malloc(pload_mgmt->size_of_group * sizeof (void *)); + if (NULL == results_array) { + ret = OMPI_ERR_OUT_OF_RESOURCE; + goto exit_ERROR; + } /* setup the input file for the shared memory connection manager */ input_file.file_name = sm_reg_data->file_name; @@ -371,6 +375,7 @@ int bcol_basesmuma_bank_init_opti(struct mca_bcol_base_memory_block_desc_t *payl /* done with the index array */ free (results_array); + results_array = NULL; /* initialize my control structures!! */ my_idx = sm_bcol_module->super.sbgp_partner_module->my_index; @@ -424,6 +429,9 @@ int bcol_basesmuma_bank_init_opti(struct mca_bcol_base_memory_block_desc_t *payl return OMPI_SUCCESS; exit_ERROR: + if (NULL != results_array) { + free(results_array); + } return ret; } diff --git a/ompi/mca/bcol/basesmuma/bcol_basesmuma_module.c b/ompi/mca/bcol/basesmuma/bcol_basesmuma_module.c index aadc7196a2..8aaed8956f 100644 --- a/ompi/mca/bcol/basesmuma/bcol_basesmuma_module.c +++ b/ompi/mca/bcol/basesmuma/bcol_basesmuma_module.c @@ -4,7 +4,7 @@ * Copyright (c) 2009-2012 Mellanox Technologies. All rights reserved. * Copyright (c) 2012-2014 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -679,6 +679,7 @@ mca_bcol_basesmuma_comm_query(mca_sbgp_base_module_t *module, int *num_modules) free(sm_module->reduction_tree); sm_module->reduction_tree=NULL; } + free(sm_modules); return NULL; } diff --git a/ompi/mca/bcol/basesmuma/bcol_basesmuma_smcm.c b/ompi/mca/bcol/basesmuma/bcol_basesmuma_smcm.c index dfeb7ef852..dae2409831 100644 --- a/ompi/mca/bcol/basesmuma/bcol_basesmuma_smcm.c +++ b/ompi/mca/bcol/basesmuma/bcol_basesmuma_smcm.c @@ -6,7 +6,7 @@ * Copyright (c) 2012-2014 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2014 Intel, Inc. All rights reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -379,11 +379,13 @@ bcol_basesmuma_smcm_mmap_t *bcol_basesmuma_smcm_mem_reg(void *in_ptr, rc = ftruncate (fd, length); if (0 > rc) { opal_output (ompi_bcol_base_framework.framework_output, "failed to truncate the file to be mapped. errno: %d", errno); + close(fd); return NULL; } map = bcol_basesmuma_smcm_reg_mmap(in_ptr, fd, length, 0, alignment, file_name); if (NULL == map) { + close(fd); return NULL; } } diff --git a/ompi/mca/bcol/ptpcoll/bcol_ptpcoll_module.c b/ompi/mca/bcol/ptpcoll/bcol_ptpcoll_module.c index ad31bd8ba4..bce153989a 100644 --- a/ompi/mca/bcol/ptpcoll/bcol_ptpcoll_module.c +++ b/ompi/mca/bcol/ptpcoll/bcol_ptpcoll_module.c @@ -4,7 +4,7 @@ * Copyright (c) 2009-2012 Mellanox Technologies. All rights reserved. * Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -754,5 +754,6 @@ mca_bcol_base_module_t **mca_bcol_ptpcoll_comm_query(mca_sbgp_base_module_t *sbg CLEANUP: OBJ_RELEASE(ptpcoll_module); + free(ptpcoll_modules); return NULL; }