linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Namhyung Kim <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: peterz@infradead.org, namhyung@kernel.org,
	linux-kernel@vger.kernel.org, mingo@kernel.org, jolsa@kernel.org,
	milian.wolff@kdab.com, yao.jin@linux.intel.com,
	tglx@linutronix.de, acme@redhat.com, hpa@zytor.com
Subject: [tip:perf/core] perf srcline: Fix memory leak in addr2inlines()
Date: Fri, 3 Nov 2017 07:23:37 -0700	[thread overview]
Message-ID: <tip-b7b75a60b291cc699ca9bb2a8517a1b3b08bbeb1@git.kernel.org> (raw)
In-Reply-To: <20171031020654.31163-1-namhyung@kernel.org>

Commit-ID:  b7b75a60b291cc699ca9bb2a8517a1b3b08bbeb1
Gitweb:     https://git.kernel.org/tip/b7b75a60b291cc699ca9bb2a8517a1b3b08bbeb1
Author:     Namhyung Kim <namhyung@kernel.org>
AuthorDate: Tue, 31 Oct 2017 11:06:53 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 1 Nov 2017 11:43:56 -0300

perf srcline: Fix memory leak in addr2inlines()

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 <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: kernel-team@lge.com
Link: http://lkml.kernel.org/r/20171031020654.31163-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 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 c143c3b..51dc49c 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;
 }

      parent reply	other threads:[~2017-11-03 14:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-31  2:06 [PATCH 1/2] perf tools: Fix memory leak in addr2inlines() Namhyung Kim
2017-10-31  2:06 ` [PATCH 2/2] perf tools: Show correct function name for srcline of callchains Namhyung Kim
     [not found]   ` <2208660.mvSdWdKhUF@milian-kdab2>
2017-11-01 12:05     ` Namhyung Kim
2017-11-01 14:41       ` Arnaldo Carvalho de Melo
2017-11-01 12:14   ` Jiri Olsa
2017-11-03 14:24   ` [tip:perf/core] perf srcline: " tip-bot for Namhyung Kim
2017-11-01 12:13 ` [PATCH 1/2] perf tools: Fix memory leak in addr2inlines() Jiri Olsa
2017-11-01 14:42   ` Arnaldo Carvalho de Melo
2017-11-03 14:23 ` tip-bot for Namhyung Kim [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-b7b75a60b291cc699ca9bb2a8517a1b3b08bbeb1@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=milian.wolff@kdab.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=yao.jin@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).