Skip to content

Commit 70533e6

Browse files
committed
fcoll/static: fix coverity issues
Fix CID 72362: Explicit null dereferenced (FORWARD_NULL) From what I can tell the code @ fcoll_static_file_read_all.c:649 should be setting bytes_per_process[i] to 0 not bytes_per_process. Fix CID 72361: Explicit null dereferenced (FORWARD_NULL) Modified check to check for blocklen_per_process non-NULL before trying to free blocklen_per_process[l]. This is sufficient because free (NULL) is safe. Also cleaned up the initialization of this an a couple other arrays. They were allocated with malloc() then initialized to 0. Changed to used calloc(). Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 8871bdb commit 70533e6

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

ompi/mca/fcoll/static/fcoll_static_file_read_all.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,40 +244,33 @@ mca_fcoll_static_file_read_all (mca_io_ompio_file_t *fh,
244244
goto exit;
245245
}
246246

247-
bytes_remaining = (int *) malloc (fh->f_procs_per_group * sizeof(int));
247+
bytes_remaining = (int *) calloc (fh->f_procs_per_group, sizeof(int));
248248
if (NULL == bytes_remaining){
249249
opal_output (1, "OUT OF MEMORY\n");
250250
ret = OMPI_ERR_OUT_OF_RESOURCE;
251251
goto exit;
252252
}
253253

254-
current_index = (int *) malloc (fh->f_procs_per_group * sizeof(int));
254+
current_index = (int *) calloc (fh->f_procs_per_group, sizeof(int));
255255
if (NULL == current_index){
256256
opal_output (1, "OUT OF MEMORY\n");
257257
ret = OMPI_ERR_OUT_OF_RESOURCE;
258258
goto exit;
259259
}
260260

261-
blocklen_per_process = (int **)malloc (fh->f_procs_per_group * sizeof (int*));
261+
blocklen_per_process = (int **)calloc (fh->f_procs_per_group, sizeof (int*));
262262
if (NULL == blocklen_per_process) {
263263
opal_output (1, "OUT OF MEMORY\n");
264264
ret = OMPI_ERR_OUT_OF_RESOURCE;
265265
goto exit;
266266
}
267267

268-
displs_per_process = (MPI_Aint **)malloc (fh->f_procs_per_group * sizeof (MPI_Aint*));
268+
displs_per_process = (MPI_Aint **)calloc (fh->f_procs_per_group, sizeof (MPI_Aint*));
269269
if (NULL == displs_per_process) {
270270
opal_output (1, "OUT OF MEMORY\n");
271271
ret = OMPI_ERR_OUT_OF_RESOURCE;
272272
goto exit;
273273
}
274-
275-
for(i=0;i<fh->f_procs_per_group;i++){
276-
current_index[i] = 0;
277-
bytes_remaining[i] = 0;
278-
blocklen_per_process[i] = NULL;
279-
displs_per_process[i] = NULL;
280-
}
281274
}
282275

283276

@@ -646,8 +639,8 @@ mca_fcoll_static_file_read_all (mca_io_ompio_file_t *fh,
646639
global_iov_count,
647640
sorted);
648641
if (current_index[i] == -1){
649-
bytes_per_process = 0; /* no more entries left
650-
to service this request*/
642+
bytes_per_process[i] = 0; /* no more entries left
643+
to service this request*/
651644
continue;
652645
}
653646
}
@@ -960,9 +953,8 @@ mca_fcoll_static_file_read_all (mca_io_ompio_file_t *fh,
960953
if (my_aggregator == fh->f_rank) {
961954

962955
for(l=0;l<fh->f_procs_per_group;l++){
963-
if (NULL != blocklen_per_process[l]){
956+
if (blocklen_per_process) {
964957
free(blocklen_per_process[l]);
965-
blocklen_per_process[l] = NULL;
966958
}
967959
if (NULL != displs_per_process[l]){
968960
free(displs_per_process[l]);

0 commit comments

Comments
 (0)