Skip to content

Commit c16e639

Browse files
committed
Merge pull request #1563 from hjelmn/ompi_coverity
ompi coverity fixes
2 parents 9511e38 + 1ff3d3b commit c16e639

File tree

5 files changed

+34
-42
lines changed

5 files changed

+34
-42
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]);

ompi/mca/fcoll/two_phase/fcoll_two_phase_file_read_all.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,9 @@ mca_fcoll_two_phase_file_read_all (mca_io_ompio_file_t *fh,
277277
}
278278
}
279279
flat_buf->count = local_size;
280-
i=0;j=0;
281-
while(j < local_size){
282-
flat_buf->indices[j] = (OMPI_MPI_OFFSET_TYPE)(intptr_t)decoded_iov[i].iov_base;
283-
flat_buf->blocklens[j] = decoded_iov[i].iov_len;
284-
285-
if(i < (int)iov_count)
286-
i+=1;
287-
288-
j+=1;
280+
for (j = 0 ; j < local_size ; ++j) {
281+
flat_buf->indices[j] = (OMPI_MPI_OFFSET_TYPE)(intptr_t)decoded_iov[j].iov_base;
282+
flat_buf->blocklens[j] = decoded_iov[j].iov_len;
289283
}
290284

291285
#if DEBUG

ompi/mca/fcoll/two_phase/fcoll_two_phase_file_write_all.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2008-2014 University of Houston. All rights reserved.
1414
* Copyright (c) 2015 Research Organization for Information Science
1515
* and Technology (RIST). All rights reserved.
16-
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
16+
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
1717
* reserved.
1818
* $COPYRIGHT$
1919
*
@@ -194,6 +194,10 @@ mca_fcoll_two_phase_file_write_all (mca_io_ompio_file_t *fh,
194194
if ( 0 < iov_count ) {
195195
decoded_iov = (struct iovec *)malloc
196196
(iov_count * sizeof(struct iovec));
197+
if (NULL == decoded_iov) {
198+
ret = OMPI_ERR_OUT_OF_RESOURCE;
199+
goto exit;
200+
}
197201
}
198202
for (ti = 0; ti < iov_count; ti ++){
199203
decoded_iov[ti].iov_base = (IOVBASE_TYPE *)(
@@ -320,19 +324,15 @@ mca_fcoll_two_phase_file_write_all (mca_io_ompio_file_t *fh,
320324
}
321325
}
322326
flat_buf->count = local_size;
323-
i=0;j=0;
324-
while(j < local_size){
327+
for (j = 0 ; j < local_size ; ++j) {
325328
if ( 0 < max_data ) {
326-
flat_buf->indices[j] = (OMPI_MPI_OFFSET_TYPE)(intptr_t)decoded_iov[i].iov_base;
327-
flat_buf->blocklens[j] = decoded_iov[i].iov_len;
329+
flat_buf->indices[j] = (OMPI_MPI_OFFSET_TYPE)(intptr_t)decoded_iov[j].iov_base;
330+
flat_buf->blocklens[j] = decoded_iov[j].iov_len;
328331
}
329332
else {
330333
flat_buf->indices[j] = 0;
331334
flat_buf->blocklens[j] = 0;
332335
}
333-
if(i < (int)iov_count)
334-
i+=1;
335-
j+=1;
336336
}
337337

338338
#if DEBUG_ON
@@ -967,14 +967,14 @@ static int two_phase_exchage_data(mca_io_ompio_file_t *fh,
967967

968968

969969
recv_types = (ompi_datatype_t **)
970-
malloc (( nprocs_recv + 1 ) * sizeof(ompi_datatype_t *));
970+
calloc (( nprocs_recv + 1 ), sizeof(ompi_datatype_t *));
971971

972972
if ( NULL == recv_types ){
973973
ret = OMPI_ERR_OUT_OF_RESOURCE;
974974
goto exit;
975975
}
976976

977-
tmp_len = (int *) malloc(fh->f_size*sizeof(int));
977+
tmp_len = (int *) calloc(fh->f_size, sizeof(int));
978978

979979
if ( NULL == tmp_len ) {
980980
ret = OMPI_ERR_OUT_OF_RESOURCE;
@@ -1005,15 +1005,13 @@ static int two_phase_exchage_data(mca_io_ompio_file_t *fh,
10051005

10061006
if ( NULL == srt_off ){
10071007
ret = OMPI_ERR_OUT_OF_RESOURCE;
1008-
free(tmp_len);
10091008
goto exit;
10101009
}
10111010

10121011
srt_len = (int *) malloc((sum+1)*sizeof(int));
10131012

10141013
if ( NULL == srt_len ) {
10151014
ret = OMPI_ERR_OUT_OF_RESOURCE;
1016-
free(tmp_len);
10171015
free(srt_off);
10181016
goto exit;
10191017
}
@@ -1029,6 +1027,7 @@ static int two_phase_exchage_data(mca_io_ompio_file_t *fh,
10291027
}
10301028

10311029
free(tmp_len);
1030+
tmp_len = NULL;
10321031

10331032
*hole = 0;
10341033
if (off != srt_off[0]){
@@ -1059,7 +1058,8 @@ static int two_phase_exchage_data(mca_io_ompio_file_t *fh,
10591058
(sizeof(mca_io_ompio_io_array_t));
10601059
if (NULL == fh->f_io_array) {
10611060
opal_output(1, "OUT OF MEMORY\n");
1062-
return OMPI_ERR_OUT_OF_RESOURCE;
1061+
ret = OMPI_ERR_OUT_OF_RESOURCE;
1062+
goto exit;
10631063
}
10641064
fh->f_io_array[0].offset =(IOVBASE_TYPE *)(intptr_t) off;
10651065
fh->f_num_of_io_entries = 1;
@@ -1182,7 +1182,13 @@ static int two_phase_exchage_data(mca_io_ompio_file_t *fh,
11821182
#endif
11831183

11841184
exit:
1185-
for (i=0; i<nprocs_recv; i++) ompi_datatype_destroy(recv_types+i);
1185+
if (recv_types) {
1186+
for (i=0; i<nprocs_recv; i++) {
1187+
if (recv_types[i]) {
1188+
ompi_datatype_destroy(recv_types+i);
1189+
}
1190+
}
1191+
}
11861192
free (recv_types);
11871193

11881194
free (requests);
@@ -1193,6 +1199,7 @@ static int two_phase_exchage_data(mca_io_ompio_file_t *fh,
11931199

11941200
free (send_buf);
11951201
}
1202+
free (tmp_len);
11961203

11971204
return ret;
11981205
}

ompi/mca/pml/ob1/pml_ob1_isend.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,6 @@ int mca_pml_ob1_send(const void *buf,
211211
return OMPI_SUCCESS;
212212
}
213213

214-
if (OPAL_UNLIKELY(NULL == endpoint)) {
215-
return OMPI_ERR_UNREACH;
216-
}
217-
218214
seqn = (uint16_t) OPAL_THREAD_ADD32(&ob1_proc->send_sequence, 1);
219215

220216
/**

ompi/mpi/fortran/mpif-h/comm_spawn_multiple_f.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Copyright (c) 2010-2012 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2015 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
16+
* reserved.
1517
* $COPYRIGHT$
1618
*
1719
* Additional copyrights may follow
@@ -150,4 +152,5 @@ void ompi_comm_spawn_multiple_f(MPI_Fint *count, char *array_commands,
150152
}
151153
}
152154
free(c_array_argv);
155+
free(c_info);
153156
}

0 commit comments

Comments
 (0)