Skip to content

Commit 25d8f48

Browse files
Taeungacmel
authored andcommitted
perf config: Constructor should free its allocated memory when failing
Because of die() at perf_parse_file() a config set was freed in collect_config(), if failed. But it is natural to free a config set after collect_config() is done when some problems happened. So, in case of failure, lastly free a config set at perf_config_set__new() instead of freeing the config set in collect_config(). Signed-off-by: Taeung Song <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent c58c49a commit 25d8f48

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tools/perf/util/config.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,6 @@ static int collect_config(const char *var, const char *value,
643643

644644
out_free:
645645
free(key);
646-
perf_config_set__delete(set);
647646
return -1;
648647
}
649648

@@ -653,7 +652,10 @@ struct perf_config_set *perf_config_set__new(void)
653652

654653
if (set) {
655654
INIT_LIST_HEAD(&set->sections);
656-
perf_config(collect_config, set);
655+
if (perf_config(collect_config, set) < 0) {
656+
perf_config_set__delete(set);
657+
set = NULL;
658+
}
657659
}
658660

659661
return set;

0 commit comments

Comments
 (0)