Skip to content

Commit d330551

Browse files
authored
Merge pull request #8146 from bosilca/fix/han_coverity
Fix HAN issues reported by Coverity.
2 parents 00ccc9d + 1541175 commit d330551

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

ompi/mca/coll/base/coll_base_comm_select.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ static opal_list_t *check_components(opal_list_t * components,
439439
/* If we didn't find any available components, return an error */
440440
if (0 == opal_list_get_size(selectable)) {
441441
OBJ_RELEASE(selectable);
442+
if( NULL != coll_exclude ) {
443+
free(coll_exclude);
444+
}
445+
if( NULL != coll_include ) {
446+
free(coll_include);
447+
}
442448
return NULL;
443449
}
444450

ompi/mca/coll/base/coll_base_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,10 @@ static const char* colltype_translation_table[] = {
551551
[COLLCOUNT] = NULL
552552
};
553553

554-
char* mca_coll_base_colltype_to_str(int collid)
554+
const char* mca_coll_base_colltype_to_str(int collid)
555555
{
556556
if( (collid < 0) || (collid >= COLLCOUNT) ) {
557557
return NULL;
558558
}
559-
return strdup(colltype_translation_table[collid]);
559+
return colltype_translation_table[collid];
560560
}

ompi/mca/coll/base/coll_base_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int ompi_coll_base_file_getnext_string(FILE *fptr, int *fileline, char** val);
187187
int ompi_coll_base_file_peek_next_char_is(FILE *fptr, int *fileline, int expected);
188188

189189
/* Miscelaneous function */
190-
char* mca_coll_base_colltype_to_str(int collid);
190+
const char* mca_coll_base_colltype_to_str(int collid);
191191
int mca_coll_base_name_to_colltype(const char* name);
192192

193193
END_C_DECLS

ompi/mca/coll/han/coll_han_dynamic_file.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,18 @@ mca_coll_han_init_dynamic_rules(void)
130130
/* maybe the file was in the old format and we read the collective index instead of the name. */
131131
char* endp;
132132
coll_id = strtol(coll_name, &endp, 10);
133-
if( '\0' != *endp ) { /* there is garbage in the input */
133+
if( ('\0' != *endp ) || (coll_id < ALLGATHER) || (coll_id >= COLLCOUNT) ) { /* there is garbage in the input */
134134
opal_output_verbose(5, mca_coll_han_component.han_output,
135135
"coll:han:mca_coll_han_init_dynamic_rules invalid collective %s "
136136
"at line %d: the collective must be at least %d and less than %d. "
137137
"The rest of the input file will be ignored.\n",
138138
coll_name, fileline, ALLGATHER, COLLCOUNT);
139139
goto file_reading_error;
140140
}
141-
free(coll_name);
142-
coll_name = mca_coll_base_colltype_to_str(coll_id);
141+
if( NULL != coll_name ) {
142+
free(coll_name);
143+
}
144+
coll_name = strdup(mca_coll_base_colltype_to_str(coll_id));
143145
}
144146

145147
if(!mca_coll_han_is_coll_dynamic_implemented(coll_id)) {
@@ -390,24 +392,26 @@ mca_coll_han_init_dynamic_rules(void)
390392
opal_output_verbose(0, mca_coll_han_component.han_output,
391393
"coll:han:mca_coll_han_init_dynamic_rules "
392394
"cannot allocate dynamic rules\n");
393-
/* Do not check free_dynamic_rules
394-
* because we are returning OMPI_ERROR anyway */
395+
if( NULL != coll_name ) {
396+
free(coll_name);
397+
}
398+
fclose (fptr);
399+
/* We disable the module, we don't need to keep the rules */
395400
mca_coll_han_free_dynamic_rules();
396401
return OMPI_ERROR;
397402

398403
file_reading_error:
399-
if( NULL != coll_name ) {
400-
free(coll_name);
401-
}
402404
opal_output_verbose(0, mca_coll_han_component.han_output,
403405
"coll:han:mca_coll_han_init_dynamic_rules "
404406
"could not fully read dynamic rules file. "
405407
"Will use mca parameters defined rules. "
406408
"To see error detail, please set "
407409
"collective verbosity level over 5\n");
408-
if(fptr) {
409-
fclose (fptr);
410+
if( NULL != coll_name ) {
411+
free(coll_name);
410412
}
413+
fclose (fptr);
414+
/* We disable the module, we don't need to keep the rules */
411415
mca_coll_han_free_dynamic_rules();
412416
return OMPI_SUCCESS;
413417
}

0 commit comments

Comments
 (0)