Skip to content

Commit eb79edf

Browse files
committed
Merge pull request #963 from hjelmn/ompi_coverity
fcoll/two_phase: fix coverity errors
2 parents dc98208 + 95b95e1 commit eb79edf

File tree

4 files changed

+130
-173
lines changed

4 files changed

+130
-173
lines changed

ompi/mca/fcoll/dynamic/fcoll_dynamic_file_write_all.c

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -366,24 +366,20 @@ mca_fcoll_dynamic_file_write_all (mca_io_ompio_file_t *fh,
366366
goto exit;
367367
}
368368

369-
blocklen_per_process = (int **)malloc (fh->f_procs_per_group * sizeof (int*));
369+
blocklen_per_process = (int **)calloc (fh->f_procs_per_group, sizeof (int*));
370370
if (NULL == blocklen_per_process) {
371371
opal_output (1, "OUT OF MEMORY\n");
372372
ret = OMPI_ERR_OUT_OF_RESOURCE;
373373
goto exit;
374374
}
375375

376-
displs_per_process = (MPI_Aint **)malloc (fh->f_procs_per_group * sizeof (MPI_Aint*));
376+
displs_per_process = (MPI_Aint **)calloc (fh->f_procs_per_group, sizeof (MPI_Aint*));
377377
if (NULL == displs_per_process) {
378378
opal_output (1, "OUT OF MEMORY\n");
379379
ret = OMPI_ERR_OUT_OF_RESOURCE;
380380
goto exit;
381381
}
382382

383-
for(i=0;i<fh->f_procs_per_group;i++){
384-
blocklen_per_process[i] = NULL;
385-
displs_per_process[i] = NULL;
386-
}
387383
recv_req = (MPI_Request *)malloc ((fh->f_procs_per_group)*sizeof(MPI_Request));
388384
if ( NULL == recv_req ) {
389385
opal_output (1, "OUT OF MEMORY\n");
@@ -439,22 +435,12 @@ mca_fcoll_dynamic_file_write_all (mca_io_ompio_file_t *fh,
439435
for(l=0;l<fh->f_procs_per_group;l++){
440436
disp_index[l] = 1;
441437

442-
if (NULL != blocklen_per_process[l]){
443-
free(blocklen_per_process[l]);
444-
blocklen_per_process[l] = NULL;
445-
}
446-
if (NULL != displs_per_process[l]){
447-
free(displs_per_process[l]);
448-
displs_per_process[l] = NULL;
449-
}
438+
free(blocklen_per_process[l]);
439+
free(displs_per_process[l]);
440+
450441
blocklen_per_process[l] = (int *) calloc (1, sizeof(int));
451-
if (NULL == blocklen_per_process[l]) {
452-
opal_output (1, "OUT OF MEMORY for blocklen\n");
453-
ret = OMPI_ERR_OUT_OF_RESOURCE;
454-
goto exit;
455-
}
456442
displs_per_process[l] = (MPI_Aint *) calloc (1, sizeof(MPI_Aint));
457-
if (NULL == displs_per_process[l]){
443+
if (NULL == displs_per_process[l] || NULL == blocklen_per_process[l]){
458444
opal_output (1, "OUT OF MEMORY for displs\n");
459445
ret = OMPI_ERR_OUT_OF_RESOURCE;
460446
goto exit;
@@ -1044,24 +1030,16 @@ exit :
10441030
global_buf = NULL;
10451031
}
10461032
for(l=0;l<fh->f_procs_per_group;l++){
1047-
if (NULL != blocklen_per_process[l]){
1033+
if (NULL != blocklen_per_process){
10481034
free(blocklen_per_process[l]);
1049-
blocklen_per_process[l] = NULL;
10501035
}
1051-
if (NULL != displs_per_process[l]){
1036+
if (NULL != displs_per_process){
10521037
free(displs_per_process[l]);
1053-
displs_per_process[l] = NULL;
10541038
}
10551039
}
1056-
if (NULL != blocklen_per_process){
1057-
free(blocklen_per_process);
1058-
blocklen_per_process = NULL;
1059-
}
1060-
if (NULL != displs_per_process){
1061-
free(displs_per_process);
1062-
displs_per_process = NULL;
1063-
}
10641040

1041+
free(blocklen_per_process);
1042+
free(displs_per_process);
10651043
}
10661044

10671045
if (NULL != displs){

ompi/mca/fcoll/two_phase/fcoll_two_phase_file_read_all.c

Lines changed: 44 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12
/*
23
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
34
* University Research and Technology
@@ -11,6 +12,8 @@
1112
* All rights reserved.
1213
* Copyright (c) 2008-2014 University of Houston. All rights reserved.
1314
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
15+
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
16+
* reserved.
1417
* $COPYRIGHT$
1518
*
1619
* Additional copyrights may follow
@@ -186,7 +189,7 @@ mca_fcoll_two_phase_file_read_all (mca_io_ompio_file_t *fh,
186189
two_phase_num_io_procs,
187190
max_data);
188191
if (OMPI_SUCCESS != ret){
189-
return ret;
192+
goto exit;
190193
}
191194

192195
two_phase_num_io_procs = fh->f_final_num_aggrs;
@@ -497,21 +500,19 @@ mca_fcoll_two_phase_file_read_all (mca_io_ompio_file_t *fh,
497500
if (flat_buf->indices != NULL){
498501
free (flat_buf->indices);
499502
}
500-
free(flat_buf);
501503
flat_buf = NULL;
502504
}
503-
if (start_offsets != NULL){
504-
free(start_offsets);
505-
start_offsets = NULL;
506-
}
507-
if (end_offsets != NULL){
508-
free(end_offsets);
509-
end_offsets = NULL;
510-
}
511-
if (aggregator_list != NULL){
512-
free(aggregator_list);
513-
aggregator_list = NULL;
514-
}
505+
506+
free (start_offsets);
507+
free (end_offsets);
508+
free (aggregator_list);
509+
free (fd_start);
510+
free (decoded_iov);
511+
free (buf_indices);
512+
free (count_my_req_per_proc);
513+
free (my_req);
514+
free (others_req);
515+
free (fd_end);
515516

516517
return ret;
517518
}
@@ -634,8 +635,8 @@ static int two_phase_read_and_exch(mca_io_ompio_file_t *fh,
634635

635636
start_pos = (int *) calloc(fh->f_size, sizeof(int));
636637
if ( NULL == start_pos ){
637-
ret = OMPI_ERR_OUT_OF_RESOURCE;
638-
return ret;
638+
ret = OMPI_ERR_OUT_OF_RESOURCE;
639+
goto exit;
639640
}
640641

641642
done = 0;
@@ -717,7 +718,8 @@ static int two_phase_read_and_exch(mca_io_ompio_file_t *fh,
717718
(1,sizeof(mca_io_ompio_io_array_t));
718719
if (NULL == fh->f_io_array) {
719720
opal_output(1, "OUT OF MEMORY\n");
720-
return OMPI_ERR_OUT_OF_RESOURCE;
721+
ret = OMPI_ERR_OUT_OF_RESOURCE;
722+
goto exit;
721723
}
722724
fh->f_io_array[0].offset = (IOVBASE_TYPE *)(intptr_t)off;
723725
fh->f_io_array[0].length = len;
@@ -728,7 +730,8 @@ static int two_phase_read_and_exch(mca_io_ompio_file_t *fh,
728730
if (fh->f_num_of_io_entries){
729731
if ( 0 > fh->f_fbtl->fbtl_preadv (fh)) {
730732
opal_output(1, "READ FAILED\n");
731-
return OMPI_ERROR;
733+
ret = OMPI_ERROR;
734+
goto exit;
732735
}
733736
}
734737

@@ -797,40 +800,17 @@ static int two_phase_read_and_exch(mca_io_ompio_file_t *fh,
797800
flat_buf, others_req, m, buf_idx,
798801
buftype_extent, striping_unit, two_phase_num_io_procs,
799802
aggregator_list);
800-
if (ntimes){
801-
free(read_buf);
802-
read_buf = NULL;
803-
}
804-
if (NULL != curr_offlen_ptr){
805-
free(curr_offlen_ptr);
806-
curr_offlen_ptr = NULL;
807-
}
808-
if (NULL != count){
809-
free(count);
810-
count = NULL;
811-
}
812-
if (NULL != partial_send){
813-
free(partial_send);
814-
partial_send = NULL;
815-
}
816-
if (NULL != send_size){
817-
free(send_size);
818-
send_size = NULL;
819-
}
820-
if (NULL != recv_size){
821-
free(recv_size);
822-
recv_size = NULL;
823-
}
824-
if (NULL != recd_from_proc){
825-
free(recd_from_proc);
826-
recd_from_proc = NULL;
827-
}
828-
if (NULL != start_pos){
829-
free(start_pos);
830-
start_pos = NULL;
831-
}
832803

833804
exit:
805+
free (read_buf);
806+
free (curr_offlen_ptr);
807+
free (count);
808+
free (partial_send);
809+
free (send_size);
810+
free (recv_size);
811+
free (recd_from_proc);
812+
free (start_pos);
813+
834814
return ret;
835815

836816
}
@@ -919,7 +899,7 @@ static int two_phase_exchange_data(mca_io_ompio_file_t *fh,
919899
}
920900
else{
921901

922-
recv_buf = (char **)malloc(fh->f_size * sizeof(char *));
902+
recv_buf = (char **) calloc (fh->f_size, sizeof(char *));
923903
if (NULL == recv_buf){
924904
ret = OMPI_ERR_OUT_OF_RESOURCE;
925905
goto exit;
@@ -983,7 +963,9 @@ static int two_phase_exchange_data(mca_io_ompio_file_t *fh,
983963
ret = ompi_request_wait_all(nprocs_recv,
984964
requests,
985965
MPI_STATUS_IGNORE);
986-
966+
if (OMPI_SUCCESS != ret) {
967+
goto exit;
968+
}
987969

988970
if (! (fh->f_flags & OMPIO_CONTIGUOUS_MEMORY)) {
989971

@@ -1001,26 +983,23 @@ static int two_phase_exchange_data(mca_io_ompio_file_t *fh,
1001983
requests+nprocs_recv,
1002984
MPI_STATUS_IGNORE);
1003985

1004-
if (NULL != requests){
1005-
free(requests);
1006-
requests = NULL;
1007-
}
986+
#if OMPIO_FCOLL_WANT_TIME_BREAKDOWN
987+
end_rcomm_time = MPI_Wtime();
988+
rcomm_time += (end_rcomm_time - start_rcomm_time);
989+
#endif
990+
991+
exit:
1008992

1009-
if (! (fh->f_flags & OMPIO_CONTIGUOUS_MEMORY)){
993+
if (recv_buf) {
1010994
for (i=0; i< fh->f_size; i++){
1011-
if (recv_size[i]){
1012-
free(recv_buf[i]);
1013-
}
995+
free(recv_buf[i]);
1014996
}
997+
1015998
free(recv_buf);
1016999
}
10171000

1018-
#if OMPIO_FCOLL_WANT_TIME_BREAKDOWN
1019-
end_rcomm_time = MPI_Wtime();
1020-
rcomm_time += (end_rcomm_time - start_rcomm_time);
1021-
#endif
1001+
free(requests);
10221002

1023-
exit:
10241003
return ret;
10251004

10261005
}

0 commit comments

Comments
 (0)