Skip to content

Commit 50a2740

Browse files
Namhyung Kimacmel
authored andcommitted
perf header: Fix possible memory leaks in process_group_desc()
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 <namhyung@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1384741244-7271-2-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 210e812 commit 50a2740

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎tools/perf/util/header.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,7 @@ static int process_group_desc(struct perf_file_section *section __maybe_unused,
21072107

21082108
ret = 0;
21092109
out_free:
2110-
while ((int) --i >= 0)
2110+
for (i = 0; i < nr_groups; i++)
21112111
free(desc[i].name);
21122112
free(desc);
21132113

0 commit comments

Comments
 (0)