Thread (4 messages) read the whole thread 4 messages, 2 authors, 2021-08-24
STALE1804d LANDED

Landed in mainline as 261f491133ae on 2021-08-30.

[PATCH] perf config: fix caching and memory leak in perf_home_perfconfig

From: Riccardo Mancini <hidden>
Date: 2021-08-20 13:09:57
Also in: lkml
Subsystem: performance events subsystem, the rest · Maintainers: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Linus Torvalds

Acaict, perf_home_perfconfig is supposed to cache the result of
home_perfconfig, which returns the default location of perfconfig for
the user, given the HOME environment variable.
However, the current implementation calls home_perfconfig every time
perf_home_perfconfig is called (so no caching is actually performed),
replacing the previous pointer, thus also causing a memory leak.

This patch adds a check of whether either config or failed is set and,
in that case, directly returns config without calling home_perfconfig at
each invocation.

Cc: Jiri Olsa <jolsa@kernel.org>
Fixes: f5f03e19ce14fc31 ("perf config: Add perf_home_perfconfig function")
Signed-off-by: Riccardo Mancini <redacted>
---
 tools/perf/util/config.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 63d472b336de21d4..6ab670cdf512507e 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -581,6 +581,9 @@ const char *perf_home_perfconfig(void)
 	static const char *config;
 	static bool failed;
 
+	if (config || failed)
+		return config;
+
 	config = failed ? NULL : home_perfconfig();
 	if (!config)
 		failed = true;
-- 
2.31.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help