From 075dfa41219b9e0f9508b1def0833f4f2d2e083a Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Fri, 18 Mar 2016 11:31:11 -0600 Subject: [PATCH] topo/treematch: fix component coverity issues Fix CID 1315298: Resource leak (RESOURCE_LEAK) : Fix CID 1315300: Resource leak (RESOURCE_LEAK): Fix CID 1315299: Resource leak (RESOURCE_LEAK): Fix CID 1315297 (#1 of 1): Resource leak (RESOURCE_LEAK): Confirmed leaks in error paths. Added the leaked arrays to the ERR_EXIT macro to ensure they are freed. Fix CID 1315296 (#1 of 1): Resource leak (RESOURCE_LEAK): Confirmed leak in error paths. Both the oversub and reqs arrays are leaked. Free these arrays on error. Signed-off-by: Nathan Hjelm --- .../topo_treematch_dist_graph_create.c | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ompi/mca/topo/treematch/topo_treematch_dist_graph_create.c b/ompi/mca/topo/treematch/topo_treematch_dist_graph_create.c index 6c31d1fa98..ef0fc4de2e 100644 --- a/ompi/mca/topo/treematch/topo_treematch_dist_graph_create.c +++ b/ompi/mca/topo/treematch/topo_treematch_dist_graph_create.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2011-2015 The University of Tennessee and The University * of Tennessee Research Foundation. All rights @@ -7,6 +8,8 @@ * Copyright (c) 2015 Intel, Inc. All rights reserved * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2016 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -31,7 +34,12 @@ #include "opal/mca/pmix/pmix.h" #define ERR_EXIT(ERR) \ - do { free(local_pattern); \ + do { \ + free (nodes_roots); \ + free (local_procs); \ + free (tracker); \ + free (colors); \ + free(local_pattern); \ return (ERR); } \ while(0); @@ -70,12 +78,20 @@ static int check_oversubscribing(int rank, oversub[0] = local_oversub; for(i = 1; i < num_nodes; i++) if (OMPI_SUCCESS != ( err = MCA_PML_CALL(irecv(&oversub[i], 1, MPI_INT, - nodes_roots[i], 111, comm_old, &reqs[i-1])))) + nodes_roots[i], 111, comm_old, &reqs[i-1])))) { + /* NTH: more needs to be done to correctly clean up here */ + free (reqs); + free (oversub); return err; + } if (OMPI_SUCCESS != ( err = ompi_request_wait_all(num_nodes-1, - reqs, MPI_STATUSES_IGNORE))) + reqs, MPI_STATUSES_IGNORE))) { + /* NTH: more needs to be done to correctly clean up here */ + free (reqs); + free (oversub); return err; + } for(i = 0; i < num_nodes; i++) oversubscribed += oversub[i];