Skip to content

Commit

Permalink
perf srcline: Fix memory leak in addr2inlines()
Browse files Browse the repository at this point in the history
When libbfd is not used, addr2inlines() executes `addr2line -i` and
process output line by line.  But it resets filename to NULL in the loop
so getline() allocates additional memory everytime instead of realloc.

Signed-off-by: Namhyung Kim <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Jin Yao <[email protected]>
Cc: Milian Wolff <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
namhyung authored and acmel committed Nov 1, 2017
1 parent 1de3038 commit b7b75a6
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions tools/perf/util/srcline.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,20 +456,17 @@ static struct inline_node *addr2inlines(const char *dso_name, u64 addr,
while (getline(&filename, &len, fp) != -1) {
char *srcline;

if (filename_split(filename, &line_nr) != 1) {
free(filename);
if (filename_split(filename, &line_nr) != 1)
goto out;
}

srcline = srcline_from_fileline(filename, line_nr);
if (inline_list__append(sym, srcline, node) != 0)
goto out;

filename = NULL;
}

out:
pclose(fp);
free(filename);

return node;
}
Expand Down

0 comments on commit b7b75a6

Please sign in to comment.