lkml.org 
[lkml]   [2017]   [Nov]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/2] perf tools: Fix memory leak in addr2inlines()
On Tue, Oct 31, 2017 at 11:06:53AM +0900, Namhyung Kim wrote:
> 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.
>
> Cc: Jin Yao <yao.jin@linux.intel.com>
> Cc: Milian Wolff <milian.wolff@kdab.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

> ---
> tools/perf/util/srcline.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
> index c143c3bc1ef8..51dc49c65476 100644
> --- a/tools/perf/util/srcline.c
> +++ b/tools/perf/util/srcline.c
> @@ -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;
> }
> --
> 2.14.3
>

\
 
 \ /
  Last update: 2017-11-01 13:14    [W:0.110 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site