All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/5] perf test: Fix a memory leak in PE file parsing test
@ 2026-10-18 16:37 Namhyung Kim
  2026-10-18 16:37 ` [PATCH v1 2/5] perf test: Make sure maps to have a machine Namhyung Kim
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Namhyung Kim @ 2026-10-18 16:37 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark, Peter Zijlstra,
	Ingo Molnar, LKML, linux-perf-users, Sashiko

The get_argv_exec_path() returns a dynamically allocated string so it
should be freed.  Let's check the return value first so that it
doesn't crash snprintf().

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/r/sashiko-outbox-168781@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/pe-file-parsing.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/perf/tests/pe-file-parsing.c b/tools/perf/tests/pe-file-parsing.c
index 190520ffc3ad6d0c..ed95aa5d8ca2af92 100644
--- a/tools/perf/tests/pe-file-parsing.c
+++ b/tools/perf/tests/pe-file-parsing.c
@@ -74,19 +74,26 @@ static int test__pe_file_parsing(struct test_suite *test __maybe_unused,
 {
 	struct stat st;
 	char path_dir[PATH_MAX];
-	const char * const tests_dirs[] = {
+	static const char * const tests_dirs[] = {
 		"./tools/perf/tests",
 		"./tests",
 		"./source/tests",
-		path_dir,
 	};
-	snprintf(path_dir, PATH_MAX, "%s/tests", get_argv_exec_path());
+	char *exec_path;
 
 	for (size_t i = 0; i < ARRAY_SIZE(tests_dirs); ++i) {
 		if (!lstat(tests_dirs[i], &st))
 			return run_dir(tests_dirs[i]);
 	}
 
+	exec_path = get_argv_exec_path();
+	TEST_ASSERT_VAL("Failed to allocate exec_path", exec_path);
+	snprintf(path_dir, PATH_MAX, "%s/tests", exec_path);
+	free(exec_path);
+
+	if (!lstat(path_dir, &st))
+		return run_dir(path_dir);
+
 	pr_debug("cannot find the tests directory\n");
 	return TEST_SKIP;
 }
-- 
2.56.0.176.g3575e65682-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-10-19  5:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-18 16:37 [PATCH v1 1/5] perf test: Fix a memory leak in PE file parsing test Namhyung Kim
2026-10-18 16:37 ` [PATCH v1 2/5] perf test: Make sure maps to have a machine Namhyung Kim
2026-10-18 16:43   ` sashiko-bot
2026-10-18 20:33   ` Ian Rogers
2026-10-19  5:36     ` Namhyung Kim
2026-10-18 16:37 ` [PATCH v1 3/5] perf tools: Remove NULL check for maps__machine() Namhyung Kim
2026-10-18 16:42   ` sashiko-bot
2026-10-18 16:37 ` [PATCH v1 4/5] perf symbol: Check result when reading section headers Namhyung Kim
2026-10-18 16:40   ` sashiko-bot
2026-10-18 16:37 ` [PATCH v1 5/5] perf symbol: Ensure dso__set_is_64_bit() for libbfd Namhyung Kim
2026-10-18 16:44   ` sashiko-bot
2026-10-19  5:38     ` Namhyung Kim
2026-10-18 16:40 ` [PATCH v1 1/5] perf test: Fix a memory leak in PE file parsing test sashiko-bot

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.