lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171031020654.31163-1-namhyung@kernel.org>
Date:   Tue, 31 Oct 2017 11:06:53 +0900
From:   Namhyung Kim <namhyung@...nel.org>
To:     Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:     Ingo Molnar <mingo@...nel.org>,
        Peter Zijlstra <a.p.zijlstra@...llo.nl>,
        Jiri Olsa <jolsa@...nel.org>,
        LKML <linux-kernel@...r.kernel.org>, kernel-team@....com,
        Jin Yao <yao.jin@...ux.intel.com>,
        Milian Wolff <milian.wolff@...b.com>
Subject: [PATCH 1/2] perf tools: 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.

Cc: Jin Yao <yao.jin@...ux.intel.com>
Cc: Milian Wolff <milian.wolff@...b.com>
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ