Skip to content

Commit 09a61c8

Browse files
namhyungacmel
authored andcommitted
perf test: Fix a memory leak in attr test
The get_argv_exec_path() returns a dynamic memory so it should be freed after use. $ perf test -v 17 ... ==141682==ERROR: LeakSanitizer: detected memory leaks Direct leak of 33 byte(s) in 1 object(s) allocated from: #0 0x7f09107d2e8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x7f091035f6a7 in __vasprintf_internal libio/vasprintf.c:71 SUMMARY: AddressSanitizer: 33 byte(s) leaked in 1 allocation(s). 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 b0faef9 commit 09a61c8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tools/perf/tests/attr.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,20 @@ int test__attr(struct test *test __maybe_unused, int subtest __maybe_unused)
182182
struct stat st;
183183
char path_perf[PATH_MAX];
184184
char path_dir[PATH_MAX];
185+
char *exec_path;
185186

186187
/* First try development tree tests. */
187188
if (!lstat("./tests", &st))
188189
return run_dir("./tests", "./perf");
189190

191+
exec_path = get_argv_exec_path();
192+
if (exec_path == NULL)
193+
return -1;
194+
190195
/* Then installed path. */
191-
snprintf(path_dir, PATH_MAX, "%s/tests", get_argv_exec_path());
196+
snprintf(path_dir, PATH_MAX, "%s/tests", exec_path);
192197
snprintf(path_perf, PATH_MAX, "%s/perf", BINDIR);
198+
free(exec_path);
193199

194200
if (!lstat(path_dir, &st) &&
195201
!lstat(path_perf, &st))

0 commit comments

Comments
 (0)