All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Li <liwei391@huawei.com>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	Jiri Olsa <jolsa@redhat.com>, Mark Rutland <mark.rutland@arm.com>,
	Namhyung Kim <namhyung@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, Li Bin <huawei.libin@huawei.com>,
	"Xie XiuQi" <xiexiuqi@huawei.com>,
	Hongbo Yao <yaohongbo@huawei.com>
Subject: [PATCH 2/4] perf svghelper: Fix memory leak in svg_build_topology_map
Date: Thu, 21 May 2020 21:32:16 +0800	[thread overview]
Message-ID: <20200521133218.30150-3-liwei391@huawei.com> (raw)
In-Reply-To: <20200521133218.30150-1-liwei391@huawei.com>

From: Li Bin <huawei.libin@huawei.com>

Fix leak of memory pointed to by t.sib_thr and t.sib_core in
svg_build_topology_map.

Signed-off-by: Li Bin <huawei.libin@huawei.com>
---
 tools/perf/util/svghelper.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index 96f941e01681..e2b3b0e2fafe 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -754,6 +754,7 @@ int svg_build_topology_map(struct perf_env *env)
 	int i, nr_cpus;
 	struct topology t;
 	char *sib_core, *sib_thr;
+	int ret;
 
 	nr_cpus = min(env->nr_cpus_online, MAX_NR_CPUS);
 
@@ -767,12 +768,14 @@ int svg_build_topology_map(struct perf_env *env)
 
 	if (!t.sib_core || !t.sib_thr) {
 		fprintf(stderr, "topology: no memory\n");
+		ret = -1;
 		goto exit;
 	}
 
 	for (i = 0; i < env->nr_sibling_cores; i++) {
 		if (str_to_bitmap(sib_core, &t.sib_core[i], nr_cpus)) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
+			ret = -1;
 			goto exit;
 		}
 
@@ -782,6 +785,7 @@ int svg_build_topology_map(struct perf_env *env)
 	for (i = 0; i < env->nr_sibling_threads; i++) {
 		if (str_to_bitmap(sib_thr, &t.sib_thr[i], nr_cpus)) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
+			ret = -1;
 			goto exit;
 		}
 
@@ -791,6 +795,7 @@ int svg_build_topology_map(struct perf_env *env)
 	topology_map = malloc(sizeof(int) * nr_cpus);
 	if (!topology_map) {
 		fprintf(stderr, "topology: no memory\n");
+		ret = -1;
 		goto exit;
 	}
 
@@ -798,12 +803,11 @@ int svg_build_topology_map(struct perf_env *env)
 		topology_map[i] = -1;
 
 	scan_core_topology(topology_map, &t, nr_cpus);
-
-	return 0;
+	ret = 0;
 
 exit:
 	zfree(&t.sib_core);
 	zfree(&t.sib_thr);
 
-	return -1;
+	return ret;
 }
-- 
2.17.1


  parent reply	other threads:[~2020-05-21 13:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 13:32 [PATCH 0/4] perf: Fix memory errors Wei Li
2020-05-21 13:32 ` [PATCH 1/4] perf metrictroup: Fix memory leak of metric_events Wei Li
2020-05-21 15:54   ` Arnaldo Carvalho de Melo
2020-05-21 16:10     ` Ian Rogers
2020-05-21 13:32 ` Wei Li [this message]
2020-05-21 14:15   ` [PATCH 2/4] perf svghelper: Fix memory leak in svg_build_topology_map Arnaldo Carvalho de Melo
2020-06-03  3:03     ` LiBin (Huawei)
2020-05-21 13:32 ` [PATCH 3/4] perf util: Fix memory leak of prefix_if_not_in Wei Li
2020-05-21 14:39   ` Arnaldo Carvalho de Melo
2020-05-21 13:32 ` [PATCH 4/4] perf util: Fix potential segment fault in put_tracepoints_path Wei Li

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=20200521133218.30150-3-liwei391@huawei.com \
    --to=liwei391@huawei.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=huawei.libin@huawei.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=namhyung@kernel.org \
    --cc=xiexiuqi@huawei.com \
    --cc=yaohongbo@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.