Skip to content

Commit fe54076

Browse files
hppritchagpaulsen
authored andcommitted
ofi: fix a memory leak in add_comm method
Fix a memory leak in ofi mtl add_comm method. Related to open-mpi#9097 Signed-off-by: Howard Pritchard <[email protected]> (cherry picked from commit 3626d64)
1 parent ef7dcbd commit fe54076

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ompi/mca/mtl/ofi/mtl_ofi.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2013-2020 Intel, Inc. All rights reserved.
3-
* Copyright (c) 2021 Triad National Security, LLC. All rights
3+
* Copyright (c) 2021-2022 Triad National Security, LLC. All rights
44
* reserved.
55
*
66
* $COPYRIGHT$
@@ -362,31 +362,34 @@ ompi_mtl_ofi_del_procs(struct mca_mtl_base_module_t *mtl,
362362
int ompi_mtl_ofi_add_comm(struct mca_mtl_base_module_t *mtl,
363363
struct ompi_communicator_t *comm)
364364
{
365-
int ret;
365+
int ret = OMPI_SUCCESS;
366366
uint32_t comm_size;
367-
mca_mtl_comm_t* mtl_comm = OBJ_NEW(mca_mtl_comm_t);
367+
mca_mtl_comm_t* mtl_comm;
368368

369369
mca_mtl_ofi_ep_type ep_type = (0 == ompi_mtl_ofi.enable_sep) ?
370370
OFI_REGULAR_EP : OFI_SCALABLE_EP;
371371

372372
if (!OMPI_COMM_IS_GLOBAL_INDEX(comm)) {
373+
mtl_comm = OBJ_NEW(mca_mtl_comm_t);
374+
373375
if (OMPI_COMM_IS_INTER(comm)) {
374376
comm_size = ompi_comm_remote_size(comm);
375377
} else {
376378
comm_size = ompi_comm_size(comm);
377379
}
378380
mtl_comm->c_index_vec = (c_index_vec_t *)malloc(sizeof(c_index_vec_t) * comm_size);
379381
if (NULL == mtl_comm->c_index_vec) {
382+
ret = OMPI_ERR_OUT_OF_RESOURCE;
380383
OBJ_RELEASE(mtl_comm);
381384
goto error;
382385
} else {
383386
for (uint32_t i=0; i < comm_size; i++) {
384-
mtl_comm->c_index_vec[i].c_index_state = 2;
387+
mtl_comm->c_index_vec[i].c_index_state = MCA_MTL_OFI_CID_NOT_EXCHANGED;
385388
}
386389
}
387390
if (OMPI_COMM_IS_INTRA(comm)) {
388391
mtl_comm->c_index_vec[comm->c_my_rank].c_index = comm->c_index;
389-
mtl_comm->c_index_vec[comm->c_my_rank].c_index_state = 0;
392+
mtl_comm->c_index_vec[comm->c_my_rank].c_index_state = MCA_MTL_OFI_CID_EXCHANGED;
390393
}
391394

392395
comm->c_mtl_comm = mtl_comm;
@@ -415,10 +418,8 @@ int ompi_mtl_ofi_add_comm(struct mca_mtl_base_module_t *mtl,
415418
}
416419
}
417420

418-
return OMPI_SUCCESS;
419-
420421
error:
421-
return OMPI_ERROR;
422+
return ret;
422423
}
423424

424425
int ompi_mtl_ofi_del_comm(struct mca_mtl_base_module_t *mtl,

0 commit comments

Comments
 (0)