Skip to content

Commit 6f31889

Browse files
authored
Merge pull request #11008 from drwootton/topo_base_cart_leak_v5
Fix multiple potential memory leaks in mca_topo_base_cart_allocate for v5.0.x
2 parents b06b1e4 + baa3bcd commit 6f31889

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ompi/mca/topo/base/topo_base_cart_create.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ static int mca_topo_base_cart_allocate (ompi_group_t *group, int ndims, const in
3535
int *my_rank, int *num_procs, mca_topo_base_comm_cart_2_2_0_t **cart_out)
3636
{
3737
mca_topo_base_comm_cart_2_2_0_t *cart = OBJ_NEW(mca_topo_base_comm_cart_2_2_0_t);
38+
if (OPAL_UNLIKELY(NULL == cart)) {
39+
return OMPI_ERR_OUT_OF_RESOURCE;
40+
}
3841
int nprocs = 1;
3942

4043
*num_procs = group->grp_proc_count;
@@ -43,13 +46,15 @@ static int mca_topo_base_cart_allocate (ompi_group_t *group, int ndims, const in
4346
/* Calculate the number of processes in this grid */
4447
for (int i = 0 ; i < ndims ; ++i) {
4548
if (dims[i] <= 0) {
49+
OBJ_RELEASE(cart);
4650
return OMPI_ERROR;
4751
}
4852
nprocs *= dims[i];
4953
}
5054

5155
/* check for the error condition */
5256
if (OPAL_UNLIKELY(*num_procs < nprocs)) {
57+
OBJ_RELEASE(cart);
5358
return MPI_ERR_DIMS;
5459
}
5560

@@ -64,13 +69,11 @@ static int mca_topo_base_cart_allocate (ompi_group_t *group, int ndims, const in
6469

6570
if (MPI_UNDEFINED == *my_rank) {
6671
/* nothing more to do */
72+
OBJ_RELEASE(cart);
6773
*cart_out = NULL;
6874
return OMPI_SUCCESS;
6975
}
7076

71-
if (OPAL_UNLIKELY(NULL == cart)) {
72-
return OMPI_ERR_OUT_OF_RESOURCE;
73-
}
7477
cart->ndims = ndims;
7578

7679
/* MPI-2.1 allows 0-dimension cartesian communicators, so prevent

0 commit comments

Comments
 (0)