Skip to contentSkip to conversation

perf test: Fix leak in "Synthesize attr update" test

PATCH Applied Ian Rogers 3 participants 3 messages Mar 5, 2025 – Mar 7, 2025 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf test: Fix leak in "Synthesize attr update" test

The own_cpus map variable may be non-NULL and hold a reference, in particular on hybrid machines. Do a put before overwriting the variable to avoid a memory leak.

---
 tools/perf/tests/event_update.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/tests/event_update.c +1 -0
index d6b4ce3ef4ee..9301fde11366 100644
@@ -109,6 +109,7 @@ static int test__event_update(struct test_suite *test __maybe_unused, int subtes
 	TEST_ASSERT_VAL("failed to synthesize attr update name",
 			!perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name));
 
+	perf_cpu_map__put(evsel->core.own_cpus);
 	evsel->core.own_cpus = perf_cpu_map__new("1,2,3");
 
 	TEST_ASSERT_VAL("failed to synthesize attr update cpus",
Signature · 1 line
2.48.1.711.g2feabab25a-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Ian Rogers

The own_cpus map variable may be non-NULL and hold a reference, in particular on hybrid machines. Do a put before overwriting the variable to avoid a memory leak.

---
  tools/perf/tests/event_update.c | 1 +
  1 file changed, 1 insertion(+)
tools/perf/tests/event_update.c +0 -0
index d6b4ce3ef4ee..9301fde11366 100644

tools/perf/tests/event_update.c static int test__event_update(struct test_suite *test __maybe_unused, int subtes · line 115

Quoted 7 lines
tools/perf/tests/event_update.c +1 -0
@@ -109,6 +109,7 @@ static int test__event_update(struct test_suite *test __maybe_unused, int subtes
  	TEST_ASSERT_VAL("failed to synthesize attr update name",
  			!perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name));
 
+	perf_cpu_map__put(evsel->core.own_cpus);
  	evsel->core.own_cpus = perf_cpu_map__new("1,2,3");
 
  	TEST_ASSERT_VAL("failed to synthesize attr update cpus",
maintainer Applied
#2 lore raw
In reply to Ian Rogers
Quoted 5 lines · Ian Rogers

The own_cpus map variable may be non-NULL and hold a reference, in particular on hybrid machines. Do a put before overwriting the variable to avoid a memory leak.

Applied to perf-tools-next, thanks!

Best regards,
Namhyung