Skip to content

Commit c8b077f

Browse files
committed
coll/ml: fix coverity issues
Fix CID 715744 (#1 of 1): Logically dead code (DEADCODE): Fix CID 715745 (#1 of 1): Logically dead code (DEADCODE): The free of scratch_num in either place is defensive programming. Instead of removing the free the conditional around the free has been removed to quiet the warning. Fix CID 715753 (#1 of 1): Dereference after null check (FORWARD_NULL): Fix CID 715778 (#1 of 1): Dereference before null check (REVERSE_INULL): Fixed the conditional to check for collective_alg != NULL instead of collective_alg->functions != NULL. Fix CID 715749 (#1 of 4): Explicit null dereferenced (FORWARD_NULL): Updated code to ensure that none of the parse functions are reached with a non-NULL value. Fix CID 715746 (#1 of 1): Logically dead code (DEADCODE): Removed dead code. Fix CID 715768 (#1 of 1): Resource leak (RESOURCE_LEAK): Fix CID 715769 (#2 of 2): Resource leak (RESOURCE_LEAK): Fix CID 715772 (#1 of 1): Resource leak (RESOURCE_LEAK): Move free calls to before error checks to cleanup leak in error paths. Fix CID 741334 (#1 of 1): Explicit null dereferenced (FORWARD_NULL): Added a check to ensure temp is not dereferenced if it is NULL. Fix CID 1196605 (#1 of 1): Bad bit shift operation (BAD_SHIFT): Fixed overflow in calculation by replacing int mask with 1ul. Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 2f4e532 commit c8b077f

File tree

4 files changed

+33
-77
lines changed

4 files changed

+33
-77
lines changed

ompi/mca/coll/ml/coll_ml_config.c

+12-28
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Copyright (c) 2009-2012 Oak Ridge National Laboratory. All rights reserved.
44
* Copyright (c) 2009-2012 Mellanox Technologies. All rights reserved.
5-
* Copyright (c) 2013-2014 Los Alamos National Security, LLC. All rights
5+
* Copyright (c) 2013-2016 Los Alamos National Security, LLC. All rights
66
* reserved.
77
* $COPYRIGHT$
88
*
@@ -440,6 +440,9 @@ static int parse_line(section_config_t *section)
440440
if (COLL_ML_CONFIG_PARSE_SINGLE_WORD == val ||
441441
COLL_ML_CONFIG_PARSE_VALUE == val) {
442442
value = strdup(coll_ml_config_yytext);
443+
if (NULL == value) {
444+
return OMPI_ERR_OUT_OF_RESOURCE;
445+
}
443446

444447
/* Now we need to see the newline */
445448
val = coll_ml_config_yylex();
@@ -458,48 +461,29 @@ static int parse_line(section_config_t *section)
458461
COLL_ML_CONFIG_PARSE_NEWLINE != val) {
459462
ML_ERROR(("Line %d, expected new line or end of line",
460463
coll_ml_config_yynewlines));
461-
ret = OMPI_ERROR;
462-
goto Error;
464+
return OMPI_ERROR;
465+
} else {
466+
ML_ERROR(("Line %d malformed", coll_ml_config_yynewlines));
467+
return OMPI_ERROR;
463468
}
464469

465470
/* Line parsing is done, read the values */
466471
if (!strcasecmp(key_buffer, "algorithm")) {
467472
ret = parse_algorithm_key(section, value);
468-
if (OMPI_SUCCESS != ret) {
469-
goto Error;
470-
}
471-
}
472-
473-
else if (!strcasecmp(key_buffer, "threshold")) {
473+
} else if (!strcasecmp(key_buffer, "threshold")) {
474474
ret = parse_threshold_key(section, value);
475-
if (OMPI_SUCCESS != ret) {
476-
goto Error;
477-
}
478-
}
479-
480-
else if (!strcasecmp(key_buffer, "hierarchy")) {
475+
} else if (!strcasecmp(key_buffer, "hierarchy")) {
481476
ret = parse_hierarchy_key(section, value);
482-
if (OMPI_SUCCESS != ret) {
483-
goto Error;
484-
}
485-
}
486-
487-
else if (!strcasecmp(key_buffer, "fragmentation")) {
477+
} else if (!strcasecmp(key_buffer, "fragmentation")) {
488478
ret = parse_fragmentation_key(section, value);
489-
if (OMPI_SUCCESS != ret) {
490-
goto Error;
491-
}
492479
/* Failed to parse the key */
493480
} else {
494481
ML_ERROR(("Line %d, unknown key %s",
495482
coll_ml_config_yynewlines, key_buffer));
496483
}
497484

498485
/* All done */
499-
Error:
500-
if (NULL != value) {
501-
free(value);
502-
}
486+
free(value);
503487

504488
return ret;
505489
}

ompi/mca/coll/ml/coll_ml_hier_algorithms_setup.c

+9-27
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Copyright (c) 2009-2012 Oak Ridge National Laboratory. All rights reserved.
44
* Copyright (c) 2009-2012 Mellanox Technologies. All rights reserved.
5-
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
5+
* Copyright (c) 2014-2016 Los Alamos National Security, LLC. All rights
66
* reserved.
77
* $COPYRIGHT$
88
*
@@ -253,32 +253,19 @@ int ml_coll_up_and_down_hier_setup(mca_coll_ml_module_t *ml_module,
253253
topo_info->hierarchical_algorithms[collective]->n_buffers = 1;
254254

255255
/* Release temporary memories */
256-
if (NULL != scratch_indx) {
257-
free(scratch_indx);
258-
}
259-
260-
if (NULL != scratch_num) {
261-
free(scratch_num);
262-
}
256+
free(scratch_indx);
257+
free(scratch_num);
263258

264259
return OMPI_SUCCESS;
265260

266261
Error:
267-
if (NULL != collective_alg->functions) {
268-
free(collective_alg->functions);
269-
}
270-
271262
if (NULL != collective_alg) {
272-
free(collective_alg);
273-
}
274-
275-
if (NULL != scratch_indx) {
276-
free(scratch_indx);
263+
free(collective_alg->functions);
277264
}
278265

279-
if (NULL != scratch_num) {
280-
free(scratch_num);
281-
}
266+
free(collective_alg);
267+
free(scratch_indx);
268+
free(scratch_num);
282269

283270
return ret;
284271
}
@@ -527,13 +514,8 @@ int ml_coll_barrier_constant_group_data_setup(
527514
return OMPI_SUCCESS;
528515

529516
Const_Data_Setup_Error:
530-
if (NULL != scratch_indx) {
531-
free(scratch_indx);
532-
}
533-
534-
if (NULL != scratch_num) {
535-
free(scratch_num);
536-
}
517+
free(scratch_indx);
518+
free(scratch_num);
537519

538520
return ret;
539521
}

ompi/mca/coll/ml/coll_ml_module.c

+9-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Copyright (c) 2009-2013 Oak Ridge National Laboratory. All rights reserved.
44
* Copyright (c) 2009-2012 Mellanox Technologies. All rights reserved.
5-
* Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights
5+
* Copyright (c) 2012-2016 Los Alamos National Security, LLC. All rights
66
* reserved.
77
* Copyright (c) 2013-2014 Cisco Systems, Inc. All rights reserved.
88
* Copyright (c) 2014 Research Organization for Information Science
@@ -476,14 +476,13 @@ static int calculate_buffer_header_size(mca_coll_ml_module_t *ml_module)
476476
MPI_INT, ompi_comm_rank(ml_module->comm),
477477
MPI_MAX, comm_size,
478478
ranks_in_comm, ml_module->comm);
479-
479+
free(ranks_in_comm);
480480
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
481481
ML_ERROR(("comm_allreduce_pml failed."));
482482
return OMPI_ERROR;
483483
}
484484

485485
ml_module->data_offset = (uint32_t) data_offset;
486-
free(ranks_in_comm);
487486

488487
ML_VERBOSE(10, ("The offset is %d", ml_module->data_offset));
489488

@@ -1105,6 +1104,10 @@ static int get_new_subgroup_data (int32_t *all_selected, int size_of_all_selecte
11051104

11061105
(*sub_group_meta_data)[sg_id].index_of_first_element=offset;
11071106

1107+
if ((*sub_group_meta_data)[sg_id].n_ranks && NULL == temp) {
1108+
return OMPI_ERROR;
1109+
}
1110+
11081111
for( array_id=0 ; array_id < (*sub_group_meta_data)[sg_id].n_ranks ;
11091112
array_id++ ) {
11101113
(*list_of_ranks_in_all_subgroups)[offset+array_id]=
@@ -1317,14 +1320,12 @@ static int ml_module_set_small_msg_thresholds(mca_coll_ml_module_t *ml_module)
13171320
BCOL_NUM_OF_FUNCTIONS, MPI_INT,
13181321
ompi_comm_rank(ml_module->comm), MPI_MIN,
13191322
comm_size, ranks_in_comm, ml_module->comm);
1320-
1323+
free(ranks_in_comm);
13211324
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
13221325
ML_ERROR(("comm_allreduce_pml failed."));
13231326
return OMPI_ERROR;
13241327
}
13251328

1326-
free(ranks_in_comm);
1327-
13281329
return OMPI_SUCCESS;
13291330
}
13301331

@@ -2319,9 +2320,6 @@ static int mca_coll_ml_fill_in_route_tab(mca_coll_ml_topology_t *topo, ompi_comm
23192320

23202321
int32_t **route_table = NULL;
23212322
int32_t *all_reachable_ranks = NULL;
2322-
2323-
struct ompi_proc_t **sbgp_procs = NULL;
2324-
23252323
mca_sbgp_base_module_t *sbgp_group = NULL;
23262324
comm_size = ompi_comm_size(comm);
23272325

@@ -2500,13 +2498,7 @@ static int mca_coll_ml_fill_in_route_tab(mca_coll_ml_topology_t *topo, ompi_comm
25002498
free(route_table);
25012499
}
25022500

2503-
if (NULL != sbgp_procs) {
2504-
free(sbgp_procs);
2505-
}
2506-
2507-
if (NULL != all_reachable_ranks) {
2508-
free(all_reachable_ranks);
2509-
}
2501+
free(all_reachable_ranks);
25102502

25112503
return rc;
25122504
}
@@ -2668,6 +2660,7 @@ static int check_for_max_supported_ml_modules(struct ompi_communicator_t *comm)
26682660
1 , MPI_INT, ompi_comm_rank(comm),
26692661
MPI_MIN, ompi_comm_size(comm), comm_ranks,
26702662
comm);
2663+
free(comm_ranks);
26712664
if (OMPI_SUCCESS != ret) {
26722665
ML_ERROR(("comm_allreduce - failed to collect max_comm data"));
26732666
return ret;
@@ -2680,8 +2673,6 @@ static int check_for_max_supported_ml_modules(struct ompi_communicator_t *comm)
26802673
--cs->max_comm;
26812674
}
26822675

2683-
free(comm_ranks);
2684-
26852676
return OMPI_SUCCESS;
26862677
}
26872678

ompi/mca/coll/ml/coll_ml_select.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Copyright (c) 2009-2013 Oak Ridge National Laboratory. All rights reserved.
44
* Copyright (c) 2009-2012 Mellanox Technologies. All rights reserved.
5-
* Copyright (c) 2012-2014 Los Alamos National Security, LLC. All rights
5+
* Copyright (c) 2012-2016 Los Alamos National Security, LLC. All rights
66
* reserved.
77
* Copyright (c) 2013-2014 Cisco Systems, Inc. All rights reserved.
88
* Copyright (c) 2014 Research Organization for Information Science
@@ -127,8 +127,7 @@ static int add_to_invoke_table(mca_bcol_base_module_t *bcol_module,
127127
struct mca_bcol_base_coll_fn_invoke_attributes_t *inv_attribs = NULL;
128128
int bcoll_type, data_src_type, waiting_semantic;
129129
int range_min,range_max;
130-
int i=0,j=0,k=0,mask=1;
131-
130+
int i=0,j=0,k=0;
132131

133132

134133
if((NULL == fn_filtered->inv_attr)||(NULL == fn_filtered->comm_attr)) {
@@ -148,7 +147,7 @@ static int add_to_invoke_table(mca_bcol_base_module_t *bcol_module,
148147
for (j=0; j<OMPI_OP_NUM_OF_TYPES; j++) {
149148
for (k=0; k<OMPI_DATATYPE_MAX_PREDEFINED; k++) {
150149

151-
if ((inv_attribs->datatype_bitmap & (mask << k)) && (inv_attribs->op_types_bitmap & (mask << j))){
150+
if ((inv_attribs->datatype_bitmap & (1ul << k)) && (inv_attribs->op_types_bitmap & (1ul << j))){
152151

153152
for (i=range_min; i<=range_max; i++) {
154153
bcol_module->filtered_fns_table[data_src_type][waiting_semantic][bcoll_type][i][j][k]

0 commit comments

Comments
 (0)