From bd28fa05ece5c8833bd41d18614c5c9e2d7b6f97 Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Thu, 10 Feb 2022 11:27:20 -0700 Subject: [PATCH] sessions: more coverity clean Related to #9097 Signed-off-by: Howard Pritchard --- ompi/communicator/comm.c | 4 +--- ompi/communicator/comm_cid.c | 9 ++++++++- ompi/errhandler/errcode.c | 26 ++++++++++++++++---------- ompi/instance/instance.c | 12 ++++++++++-- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/ompi/communicator/comm.c b/ompi/communicator/comm.c index d0397f0a3b6..b49790d85f3 100644 --- a/ompi/communicator/comm.c +++ b/ompi/communicator/comm.c @@ -24,7 +24,7 @@ * Copyright (c) 2015 Mellanox Technologies. All rights reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. * Copyright (c) 2021 Nanook Consulting. All rights reserved. - * Copyright (c) 2018-2021 Triad National Security, LLC. All rights + * Copyright (c) 2018-2022 Triad National Security, LLC. All rights * reserved. * $COPYRIGHT$ * @@ -1546,8 +1546,6 @@ int ompi_intercomm_create_from_groups (ompi_group_t *local_group, int local_lead } else { free (leader_procs); } - - rsize = remote_group->grp_proc_count; } /* bcast size and list of remote processes to all processes in local_comm */ diff --git a/ompi/communicator/comm_cid.c b/ompi/communicator/comm_cid.c index 4481c5c5dad..ae989ca0eec 100644 --- a/ompi/communicator/comm_cid.c +++ b/ompi/communicator/comm_cid.c @@ -24,7 +24,7 @@ * Copyright (c) 2017 Mellanox Technologies. All rights reserved. * Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved. * Copyright (c) 2021 Nanook Consulting. All rights reserved. - * Copyright (c) 2020-2021 Triad National Security, LLC. All rights + * Copyright (c) 2020-2022 Triad National Security, LLC. All rights * reserved. * $COPYRIGHT$ * @@ -369,6 +369,13 @@ static int ompi_comm_nextcid_ext_nb (ompi_communicator_t *newcomm, ompi_communic bool is_new_block = false; int rc; + /* + * sanity check and coverity pacifier + */ + if (!(OMPI_COMM_CID_GROUP == mode || OMPI_COMM_CID_GROUP_NEW == mode) && (NULL == comm)) { + return OMPI_ERROR; + } + if (OMPI_COMM_CID_GROUP == mode || OMPI_COMM_CID_GROUP_NEW == mode) { /* new block belongs to the new communicator */ block = &newcomm->c_contextidb; diff --git a/ompi/errhandler/errcode.c b/ompi/errhandler/errcode.c index 995acac6d0c..3a1d7865f18 100644 --- a/ompi/errhandler/errcode.c +++ b/ompi/errhandler/errcode.c @@ -13,11 +13,11 @@ * Copyright (c) 2006 University of Houston. All rights reserved. * Copyright (c) 2010-2012 Oak Ridge National Labs. All rights reserved. * Copyright (c) 2013-2018 Cisco Systems, Inc. All rights reserved - * Copyright (c) 2013 Los Alamos National Security, LLC. All rights + * Copyright (c) 2013-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. - * Copyright (c) 2018 Los Alamos National Security, LLC. All rights + * Copyright (c) 2022 Triad National Security, LLC. All rights * reserved. * $COPYRIGHT$ * @@ -140,14 +140,14 @@ do { \ opal_pointer_array_set_item(&ompi_mpi_errcodes, (ERRCODE), &(VAR)); \ } while (0) -static opal_mutex_t errcode_init_lock = OPAL_MUTEX_STATIC_INIT; +static opal_mutex_t errcode_lock = OPAL_MUTEX_STATIC_INIT; int ompi_mpi_errcode_init (void) { - opal_mutex_lock(&errcode_init_lock); + opal_mutex_lock(&errcode_lock); if ( 0 != ompi_mpi_errcode_lastpredefined ) { /* Already initialized (presumably by an API call before MPI_init */ - opal_mutex_unlock(&errcode_init_lock); + opal_mutex_unlock(&errcode_lock); return OMPI_SUCCESS; } @@ -247,7 +247,7 @@ int ompi_mpi_errcode_init (void) ompi_mpi_errcode_lastused = MPI_ERR_LASTCODE; ompi_mpi_errcode_lastpredefined = MPI_ERR_LASTCODE; - opal_mutex_unlock(&errcode_init_lock); + opal_mutex_unlock(&errcode_lock); ompi_mpi_instance_append_finalize (ompi_mpi_errcode_finalize); @@ -266,7 +266,7 @@ int ompi_mpi_errcode_finalize (void) int i; ompi_mpi_errcode_t *errc; - opal_mutex_lock(&errcode_init_lock); + opal_mutex_lock(&errcode_lock); for (i=ompi_mpi_errcode_lastpredefined+1; i<=ompi_mpi_errcode_lastused; i++) { /* * there are some user defined error-codes, which @@ -359,7 +359,7 @@ int ompi_mpi_errcode_finalize (void) OBJ_DESTRUCT(&ompi_mpi_errcodes); ompi_mpi_errcode_lastpredefined = 0; - opal_mutex_unlock(&errcode_init_lock); + opal_mutex_unlock(&errcode_lock); return OMPI_SUCCESS; } @@ -368,11 +368,14 @@ int ompi_mpi_errcode_add(int errclass ) ompi_mpi_errcode_t *newerrcode; newerrcode = OBJ_NEW(ompi_mpi_errcode_t); + + opal_mutex_lock(&errcode_lock); newerrcode->code = (ompi_mpi_errcode_lastused+1); newerrcode->cls = errclass; opal_pointer_array_set_item(&ompi_mpi_errcodes, newerrcode->code, newerrcode); - ompi_mpi_errcode_lastused++; + opal_mutex_unlock(&errcode_lock); + return newerrcode->code; } @@ -381,10 +384,13 @@ int ompi_mpi_errclass_add(void) ompi_mpi_errcode_t *newerrcode; newerrcode = OBJ_NEW(ompi_mpi_errcode_t); + + opal_mutex_lock(&errcode_lock); newerrcode->cls = ( ompi_mpi_errcode_lastused+1); opal_pointer_array_set_item(&ompi_mpi_errcodes, newerrcode->cls, newerrcode); - ompi_mpi_errcode_lastused++; + opal_mutex_unlock(&errcode_lock); + return newerrcode->cls; } diff --git a/ompi/instance/instance.c b/ompi/instance/instance.c index 6e3b363b254..56956b6982c 100644 --- a/ompi/instance/instance.c +++ b/ompi/instance/instance.c @@ -1,6 +1,6 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2018-2021 Triad National Security, LLC. All rights + * Copyright (c) 2018-2022 Triad National Security, LLC. All rights * reserved. * $COPYRIGHT$ * @@ -236,6 +236,7 @@ int ompi_mpi_instance_retain (void) OBJ_CONSTRUCT(&ompi_instance_f_to_c_table, opal_pointer_array_t); if (OPAL_SUCCESS != opal_pointer_array_init (&ompi_instance_f_to_c_table, 8, OMPI_FORTRAN_HANDLE_MAX, 32)) { + opal_mutex_unlock (&instance_lock); return OMPI_ERROR; } @@ -964,6 +965,10 @@ static void ompi_instance_get_num_psets_complete (pmix_status_t status, if (ompi_mpi_instance_pmix_psets) { opal_argv_free (ompi_mpi_instance_pmix_psets); } + if (NULL != pset_names) { + free(pset_names); + pset_names = NULL; + } PMIX_VALUE_UNLOAD(rc, &info[n].value, (void **)&pset_names, @@ -975,11 +980,14 @@ static void ompi_instance_get_num_psets_complete (pmix_status_t status, } ompi_mpi_instance_pmix_psets = opal_argv_split (pset_names, ','); ompi_mpi_instance_num_pmix_psets = opal_argv_count (ompi_mpi_instance_pmix_psets); - free(pset_names); } } done: + if (NULL != pset_names) { + free(pset_names); + } + if (NULL != release_fn) { release_fn(release_cbdata); }