Skip to content

Commit 641b625

Browse files
namhyungacmel
authored andcommitted
perf test: Fix a memory leak in thread_map_remove test
The str should be freed after creating a thread map. Also change the open-coded thread map deletion to a call to perf_thread_map__put(). $ perf test -v 44 44: Remove thread map : --- start --- test child forked, pid 165536 2 threads: 165535, 165536 1 thread: 165536 0 thread: ================================================================= ==165536==ERROR: LeakSanitizer: detected memory leaks Direct leak of 14 byte(s) in 1 object(s) allocated from: #0 0x7f54453ffe8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x7f5444f8c6a7 in __vasprintf_internal libio/vasprintf.c:71 SUMMARY: AddressSanitizer: 14 byte(s) leaked in 1 allocation(s). test child finished with 1 ---- end ---- Remove thread map: FAILED! Signed-off-by: Namhyung Kim <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4be4288 commit 641b625

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

tools/perf/tests/thread-map.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ int test__thread_map_remove(struct test *test __maybe_unused, int subtest __mayb
110110
{
111111
struct perf_thread_map *threads;
112112
char *str;
113-
int i;
114113

115114
TEST_ASSERT_VAL("failed to allocate map string",
116115
asprintf(&str, "%d,%d", getpid(), getppid()) >= 0);
117116

118117
threads = thread_map__new_str(str, NULL, 0, false);
118+
free(str);
119119

120120
TEST_ASSERT_VAL("failed to allocate thread_map",
121121
threads);
@@ -142,9 +142,6 @@ int test__thread_map_remove(struct test *test __maybe_unused, int subtest __mayb
142142
TEST_ASSERT_VAL("failed to not remove thread",
143143
thread_map__remove(threads, 0));
144144

145-
for (i = 0; i < threads->nr; i++)
146-
zfree(&threads->map[i].comm);
147-
148-
free(threads);
145+
perf_thread_map__put(threads);
149146
return 0;
150147
}

0 commit comments

Comments
 (0)