@@ -1114,6 +1114,16 @@ int ompi_dpm_finalize(void)
11141114 return OMPI_SUCCESS ;
11151115}
11161116
1117+ static void cleanup_dpm_disconnect_objs (ompi_dpm_disconnect_obj * * objs , int count )
1118+ {
1119+ for (int i = 0 ; i < count ; i ++ ) {
1120+ if (NULL != objs [i ]-> reqs ) {
1121+ free (objs [i ]-> reqs );
1122+ }
1123+ free (objs [i ]);
1124+ }
1125+ free (objs );
1126+ }
11171127
11181128/**********************************************************************/
11191129/**********************************************************************/
@@ -1127,7 +1137,7 @@ int ompi_dpm_dyn_finalize(void)
11271137 ompi_communicator_t * comm = NULL ;
11281138
11291139 if (1 < ompi_comm_num_dyncomm ) {
1130- objs = (ompi_dpm_disconnect_obj * * )malloc (( ompi_comm_num_dyncomm + 1 ) *
1140+ objs = (ompi_dpm_disconnect_obj * * )malloc (ompi_comm_num_dyncomm *
11311141 sizeof (ompi_dpm_disconnect_obj * ));
11321142 if (NULL == objs ) {
11331143 return OMPI_ERR_OUT_OF_RESOURCE ;
@@ -1138,23 +1148,15 @@ int ompi_dpm_dyn_finalize(void)
11381148 comm = (ompi_communicator_t * )opal_pointer_array_get_item (& ompi_mpi_communicators ,i );
11391149 if (NULL != comm && OMPI_COMM_IS_DYNAMIC (comm )) {
11401150 objs [j ++ ] = disconnect_init (comm );
1141- // printf ("%d/%d = %p\n", j-1, ompi_comm_num_dyncomm + 1, objs[j-1]);
11421151 }
11431152 }
11441153
1145- if (j != ompi_comm_num_dyncomm + 1 ) {
1146- for (i = 0 ; i < j ; i ++ ) {
1147- if (NULL != objs [i ]-> reqs ) {
1148- free (objs [i ]-> reqs );
1149- }
1150- free (objs [i ]);
1151- }
1152- free (objs );
1154+ if (j != ompi_comm_num_dyncomm ) {
1155+ cleanup_dpm_disconnect_objs (objs , j );
11531156 return OMPI_ERROR ;
11541157 }
11551158
1156- disconnect_waitall (ompi_comm_num_dyncomm + 1 , objs );
1157- free (objs );
1159+ disconnect_waitall (ompi_comm_num_dyncomm , objs );
11581160 }
11591161
11601162 return OMPI_SUCCESS ;
@@ -1181,7 +1183,6 @@ static ompi_dpm_disconnect_obj *disconnect_init(ompi_communicator_t *comm)
11811183 int i ;
11821184
11831185 obj = (ompi_dpm_disconnect_obj * )calloc (1 ,sizeof (ompi_dpm_disconnect_obj ));
1184- // printf("obj = %p\n", obj);
11851186 if (NULL == obj ) {
11861187 opal_output (0 , "Could not allocate disconnect object" );
11871188 return NULL ;
@@ -1274,14 +1275,7 @@ static int disconnect_waitall (int count, ompi_dpm_disconnect_obj **objs)
12741275 ret = ompi_request_wait_all (2 * totalcount , reqs , MPI_STATUSES_IGNORE );
12751276
12761277 /* Finally, free everything */
1277- for (i = 0 ; i < count ; i ++ ) {
1278- if (NULL != objs [i ]-> reqs ) {
1279- free (objs [i ]-> reqs );
1280- }
1281- // printf("%d/%d free %p\n", i, count, objs[i]);
1282- free (objs [i ]);
1283- }
1284-
1278+ cleanup_dpm_disconnect_objs (objs , count );
12851279 free (reqs );
12861280
12871281 return ret ;
0 commit comments