Skip to content

Commit 3eac4b0

Browse files
committed
communicator: Refine ompi_comm_set error check
The `ompi_comm_set` function never sets `NULL` to its first argument `ncomm`. So `NULL` check is unnecessary in its callers. Furthermore, `NULL` check may obscure a real return code when an error occurs if the variable is initialized to a `NULL` value. Also, `NULL` check is added in the `ompi_comm_set` function to avoid segmentation fault in an out-of-memory condition. Signed-off-by: KAWASHIMA Takahiro <[email protected]>
1 parent ebc4eb3 commit 3eac4b0

File tree

4 files changed

+7
-30
lines changed

4 files changed

+7
-30
lines changed

ompi/communicator/comm.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ int ompi_comm_set_nb ( ompi_communicator_t **ncomm,
158158

159159
/* ompi_comm_allocate */
160160
newcomm = OBJ_NEW(ompi_communicator_t);
161+
if (NULL == newcomm) {
162+
return OMPI_ERR_OUT_OF_RESOURCE;
163+
}
161164
newcomm->super.s_info = NULL;
162165
/* fill in the inscribing hyper-cube dimensions */
163166
newcomm->c_cube_dim = opal_cube_dim(local_size);
@@ -354,11 +357,6 @@ int ompi_comm_create ( ompi_communicator_t *comm, ompi_group_t *group,
354357
goto exit;
355358
}
356359

357-
if ( NULL == newcomm ) {
358-
rc = MPI_ERR_INTERN;
359-
goto exit;
360-
}
361-
362360
/* Determine context id. It is identical to f_2_c_handle */
363361
rc = ompi_comm_nextcid (newcomp, comm, NULL, NULL, NULL, false, mode);
364362
if ( OMPI_SUCCESS != rc ) {
@@ -580,10 +578,6 @@ int ompi_comm_split( ompi_communicator_t* comm, int color, int key,
580578
local_group, /* local group */
581579
remote_group); /* remote group */
582580

583-
if ( NULL == newcomp ) {
584-
rc = MPI_ERR_INTERN;
585-
goto exit;
586-
}
587581
if ( OMPI_SUCCESS != rc ) {
588582
goto exit;
589583
}
@@ -1004,11 +998,7 @@ int ompi_comm_dup_with_info ( ompi_communicator_t * comm, opal_info_t *info, omp
1004998
true, /* copy the topo */
1005999
comm->c_local_group, /* local group */
10061000
remote_group ); /* remote group */
1007-
if ( NULL == newcomp ) {
1008-
rc = MPI_ERR_INTERN;
1009-
return rc;
1010-
}
1011-
if ( MPI_SUCCESS != rc) {
1001+
if ( OMPI_SUCCESS != rc) {
10121002
return rc;
10131003
}
10141004

@@ -1103,7 +1093,7 @@ static int ompi_comm_idup_internal (ompi_communicator_t *comm, ompi_group_t *gro
11031093
group, /* local group */
11041094
remote_group, /* remote group */
11051095
subreq); /* new subrequest */
1106-
if (NULL == context->newcomp) {
1096+
if (OMPI_SUCCESS != rc) {
11071097
ompi_comm_request_return (request);
11081098
return rc;
11091099
}
@@ -1210,11 +1200,7 @@ int ompi_comm_create_group (ompi_communicator_t *comm, ompi_group_t *group, int
12101200
true, /* copy the topo */
12111201
group, /* local group */
12121202
NULL); /* remote group */
1213-
if ( NULL == newcomp ) {
1214-
rc = MPI_ERR_INTERN;
1215-
return rc;
1216-
}
1217-
if ( MPI_SUCCESS != rc) {
1203+
if ( OMPI_SUCCESS != rc) {
12181204
return rc;
12191205
}
12201206

ompi/dpm/dpm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,7 @@ int ompi_dpm_connect_accept(ompi_communicator_t *comm, int root,
467467
group, /* local group */
468468
new_group_pointer /* remote group */
469469
);
470-
if ( NULL == newcomp ) {
471-
rc = OMPI_ERR_OUT_OF_RESOURCE;
470+
if (OMPI_SUCCESS != rc) {
472471
goto exit;
473472
}
474473

ompi/mpi/c/intercomm_create.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader,
190190
new_group_pointer /* remote group */
191191
);
192192

193-
if ( NULL == newcomp ) {
194-
rc = MPI_ERR_INTERN;
195-
goto err_exit;
196-
}
197193
if ( MPI_SUCCESS != rc ) {
198194
goto err_exit;
199195
}

ompi/mpi/c/intercomm_merge.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ int MPI_Intercomm_merge(MPI_Comm intercomm, int high,
109109
new_group_pointer, /* local group */
110110
NULL /* remote group */
111111
);
112-
if ( NULL == newcomp ) {
113-
rc = MPI_ERR_INTERN;
114-
goto exit;
115-
}
116112
if ( MPI_SUCCESS != rc ) {
117113
goto exit;
118114
}

0 commit comments

Comments
 (0)