From 9107bf50776d540f50c29a1e263d5d40f16fe806 Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Mon, 9 Mar 2015 15:22:22 +0900 Subject: [PATCH] ompi/topo: fix misc errors as reported by Coverity with CIDs 1041232, 1041234, 1041235 1269789 and 1269996 --- ompi/mca/topo/base/topo_base_cart_create.c | 11 ++++++----- ompi/mca/topo/base/topo_base_dist_graph_create.c | 12 +++++++----- ompi/mca/topo/base/topo_base_graph_create.c | 10 ++++++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/ompi/mca/topo/base/topo_base_cart_create.c b/ompi/mca/topo/base/topo_base_cart_create.c index 6a678da7ca..6d1c732579 100644 --- a/ompi/mca/topo/base/topo_base_cart_create.c +++ b/ompi/mca/topo/base/topo_base_cart_create.c @@ -14,7 +14,7 @@ * Copyright (c) 2012-2013 Inria. All rights reserved. * Copyright (c) 2014 Los Alamos National Security, LLC. All right * 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$ * @@ -91,7 +91,6 @@ int mca_topo_base_cart_create(mca_topo_base_module_t *topo, cart = OBJ_NEW(mca_topo_base_comm_cart_2_2_0_t); if( NULL == cart ) { - ompi_comm_free(&new_comm); return OMPI_ERR_OUT_OF_RESOURCE; } cart->ndims = ndims; @@ -172,11 +171,13 @@ int mca_topo_base_cart_create(mca_topo_base_module_t *topo, new_rank, num_procs, topo_procs); if (OMPI_SUCCESS != ret) { /* something wrong happened during setting the communicator */ - new_comm->c_topo = NULL; - new_comm->c_flags &= ~OMPI_COMM_CART; free(topo_procs); OBJ_RELEASE(cart); - ompi_comm_free (&new_comm); + if (MPI_COMM_NULL != new_comm) { + new_comm->c_topo = NULL; + new_comm->c_flags &= ~OMPI_COMM_CART; + ompi_comm_free (&new_comm); + } return ret; } diff --git a/ompi/mca/topo/base/topo_base_dist_graph_create.c b/ompi/mca/topo/base/topo_base_dist_graph_create.c index 43adf1ab04..dc676e3b01 100644 --- a/ompi/mca/topo/base/topo_base_dist_graph_create.c +++ b/ompi/mca/topo/base/topo_base_dist_graph_create.c @@ -8,7 +8,7 @@ * reserved. * Copyright (c) 2011-2013 Inria. All rights reserved. * Copyright (c) 2011-2013 Université Bordeaux 1 - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. */ @@ -347,12 +347,14 @@ int mca_topo_base_dist_graph_create(mca_topo_base_module_t* module, if ( NULL != topo->outw ) { free(topo->outw); } + if (MPI_COMM_NULL != new_comm) { + new_comm->c_topo->mtc.dist_graph = NULL; + new_comm->c_topo = NULL; + new_comm->c_flags &= ~OMPI_COMM_DIST_GRAPH; + ompi_comm_free (&new_comm); + } free(topo); free(topo_procs); - new_comm->c_topo = NULL; - new_comm->c_flags &= ~OMPI_COMM_DIST_GRAPH; - new_comm->c_topo->mtc.dist_graph = NULL; - ompi_comm_free (&new_comm); return ret; } *newcomm = new_comm; diff --git a/ompi/mca/topo/base/topo_base_graph_create.c b/ompi/mca/topo/base/topo_base_graph_create.c index 990ac7228f..77a1be61d7 100644 --- a/ompi/mca/topo/base/topo_base_graph_create.c +++ b/ompi/mca/topo/base/topo_base_graph_create.c @@ -11,7 +11,7 @@ * All rights reserved. * Copyright (c) 2012-2013 Inria. All rights reserved. * Copyright (c) 2014 Cisco Systems, 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$ * @@ -131,11 +131,13 @@ int mca_topo_base_graph_create(mca_topo_base_module_t *topo, ret = ompi_comm_enable(old_comm, new_comm, new_rank, num_procs, topo_procs); if (OMPI_SUCCESS != ret) { - new_comm->c_topo = NULL; - new_comm->c_flags &= ~OMPI_COMM_GRAPH; free(topo_procs); OBJ_RELEASE(graph); - ompi_comm_free (&new_comm); + if (MPI_COMM_NULL != new_comm) { + new_comm->c_topo = NULL; + new_comm->c_flags &= ~OMPI_COMM_GRAPH; + ompi_comm_free (&new_comm); + } return ret; }