Skip to content

Commit

Permalink
perf header: Fix possible memory leaks in process_group_desc()
Browse files Browse the repository at this point in the history
After processing all group descriptors or encountering an error, it
frees all descriptors.  However, current logic can leak memory since it
might not traverse all descriptors.

Note that the 'i' can have different value than nr_groups when an error
occurred and it's safe to call free(desc[i].name) for every desc since
we already make it NULL when it's reused for group names.

Signed-off-by: Namhyung Kim <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
Namhyung Kim authored and acmel committed Nov 19, 2013
1 parent 210e812 commit 50a2740
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/perf/util/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ static int process_group_desc(struct perf_file_section *section __maybe_unused,

ret = 0;
out_free:
while ((int) --i >= 0)
for (i = 0; i < nr_groups; i++)
free(desc[i].name);
free(desc);

Expand Down

0 comments on commit 50a2740

Please sign in to comment.