Skip to content

Commit 2ae4288

Browse files
committed
coll/tuned: Prevent memory leak during tuning-file read error
During a failed json tuning file read, it was possible to leak some json structures. Explicitly destroy them all on any error path. Fixes Coverity issues 1646446, 1646447, 1646441, and 1643439 Signed-off-by: Luke Robison <[email protected]>
1 parent 01da1c4 commit 2ae4288

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

ompi/mca/coll/tuned/coll_tuned_dynamic_file.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,11 @@ static int ompi_coll_tuned_read_rules_json (const opal_json_t *json_root, ompi_c
244244

245245
const opal_json_t *collectives_obj = NULL;
246246
const opal_json_t *comm_rule_array = NULL;
247+
const opal_json_t *comm_rule = NULL;
248+
const opal_json_t *msg_size_array = NULL;
247249

248250
size_t num_collectives = 0;
249-
size_t num_comm_rules;
251+
size_t num_comm_rules = 0;
250252
rc = opal_json_get_key(json_root, "collectives", &collectives_obj);
251253
if (rc != OPAL_SUCCESS) {
252254
opal_output_verbose(1, ompi_coll_tuned_stream,
@@ -269,15 +271,14 @@ static int ompi_coll_tuned_read_rules_json (const opal_json_t *json_root, ompi_c
269271
opal_output_verbose(1, ompi_coll_tuned_stream,
270272
"Internal json error when attempting to parse the collective at index %ld\n",
271273
jcol);
272-
goto error_bad_coll;
274+
goto error_cleanup;
273275
}
274276
coll_id = mca_coll_base_name_to_colltype(coll_name);
275277
if (coll_id < 0) {
276278
opal_output_verbose(1, ompi_coll_tuned_stream,
277279
"Unrecognized collective: \"%s\". Use all lowercase such as \"allgather\"",
278280
coll_name);
279-
opal_json_free(&comm_rule_array);
280-
goto error_bad_coll;
281+
goto error_cleanup;
281282
}
282283

283284
alg_p = &alg_rules[coll_id];
@@ -287,14 +288,12 @@ static int ompi_coll_tuned_read_rules_json (const opal_json_t *json_root, ompi_c
287288
opal_output_verbose(1, ompi_coll_tuned_stream,
288289
"Problem parsing the collective at index %ld (for %s). Expected an array of comm-related rules.",
289290
jcol, mca_coll_base_colltype_to_str(coll_id) );
290-
goto error_bad_coll;
291+
goto error_cleanup;
291292
}
292293
alg_p->n_com_sizes = (int)num_comm_rules;
293294
alg_p->com_rules = ompi_coll_tuned_mk_com_rules (num_comm_rules, coll_id);
294295

295296
for (jcomm_rule=0; jcomm_rule < num_comm_rules; jcomm_rule++) {
296-
const opal_json_t *comm_rule;
297-
const opal_json_t *msg_size_array;
298297
size_t num_msg_rules;
299298
rc = opal_json_get_index(comm_rule_array, jcomm_rule, &comm_rule);
300299
com_p = &(alg_p->com_rules[jcomm_rule]);
@@ -353,15 +352,16 @@ static int ompi_coll_tuned_read_rules_json (const opal_json_t *json_root, ompi_c
353352
"Problem occurred within collective %s, "
354353
"comm_size_min=%d, comm_size_max=%d (entry number %ld in the comm_size array), "
355354
"message size entry number %ld.", coll_name, com_p->mpi_comsize_min, com_p->mpi_comsize_max, 1+jcomm_rule, 1+jmsg_rule);
356-
opal_json_free(&collectives_obj);
357-
return OMPI_ERROR;
355+
goto error_cleanup;
358356
error_bad_comm_rule:
359357
opal_output_verbose(1, ompi_coll_tuned_stream,
360358
"Problem occurred within collective %s, "
361359
"in entry number %ld of the comm_size array", coll_name, 1+jcomm_rule);
362-
opal_json_free(&collectives_obj);
363-
return OMPI_ERROR;
364-
error_bad_coll:
360+
goto error_cleanup;
361+
error_cleanup:
362+
opal_json_free(&msg_size_array);
363+
opal_json_free(&comm_rule);
364+
opal_json_free(&comm_rule_array);
365365
opal_json_free(&collectives_obj);
366366
return OMPI_ERROR;
367367
}

0 commit comments

Comments
 (0)