summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorYang Jihong <yangjihong1@huawei.com>2024-02-06 08:32:25 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-10-17 15:24:12 +0200
commite649fb7f8361ce23f4302231e14d0792ca7619a6 (patch)
treefe9833597b5c041bbbb4d6d1dfaa0967b6a93b3f /tools
parent85ca3d45bd402b1b252e17b34ca0052d2a523cd3 (diff)
downloadlinux-rpi-e649fb7f8361ce23f4302231e14d0792ca7619a6.tar.gz
linux-rpi-e649fb7f8361ce23f4302231e14d0792ca7619a6.tar.bz2
linux-rpi-e649fb7f8361ce23f4302231e14d0792ca7619a6.zip
perf sched: Fix memory leak in perf_sched__map()
[ Upstream commit ef76a5af819743d405674f6de5d0e63320ac653e ] perf_sched__map() needs to free memory of map_cpus, color_pids and color_cpus in normal path and rollback allocated memory in error path. Signed-off-by: Yang Jihong <yangjihong1@huawei.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20240206083228.172607-3-yangjihong1@huawei.com Stable-dep-of: 1a5efc9e13f3 ("libsubcmd: Don't free the usage string") Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-sched.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 2d36b06d4d87..8143828fdc58 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -3252,8 +3252,6 @@ static int perf_sched__lat(struct perf_sched *sched)
static int setup_map_cpus(struct perf_sched *sched)
{
- struct perf_cpu_map *map;
-
sched->max_cpu.cpu = sysconf(_SC_NPROCESSORS_CONF);
if (sched->map.comp) {
@@ -3262,16 +3260,15 @@ static int setup_map_cpus(struct perf_sched *sched)
return -1;
}
- if (!sched->map.cpus_str)
- return 0;
-
- map = perf_cpu_map__new(sched->map.cpus_str);
- if (!map) {
- pr_err("failed to get cpus map from %s\n", sched->map.cpus_str);
- return -1;
+ if (sched->map.cpus_str) {
+ sched->map.cpus = perf_cpu_map__new(sched->map.cpus_str);
+ if (!sched->map.cpus) {
+ pr_err("failed to get cpus map from %s\n", sched->map.cpus_str);
+ zfree(&sched->map.comp_cpus);
+ return -1;
+ }
}
- sched->map.cpus = map;
return 0;
}
@@ -3311,20 +3308,34 @@ static int setup_color_cpus(struct perf_sched *sched)
static int perf_sched__map(struct perf_sched *sched)
{
+ int rc = -1;
+
if (setup_map_cpus(sched))
- return -1;
+ return rc;
if (setup_color_pids(sched))
- return -1;
+ goto out_put_map_cpus;
if (setup_color_cpus(sched))
- return -1;
+ goto out_put_color_pids;
setup_pager();
if (perf_sched__read_events(sched))
- return -1;
+ goto out_put_color_cpus;
+
+ rc = 0;
print_bad_events(sched);
- return 0;
+
+out_put_color_cpus:
+ perf_cpu_map__put(sched->map.color_cpus);
+
+out_put_color_pids:
+ perf_thread_map__put(sched->map.color_pids);
+
+out_put_map_cpus:
+ zfree(&sched->map.comp_cpus);
+ perf_cpu_map__put(sched->map.cpus);
+ return rc;
}
static int perf_sched__replay(struct perf_sched *sched)