diff mbox series

[05/23] libtracefs: Free tracing_dir in case of remount

Message ID 20231228203714.53294-6-rostedt@goodmis.org (mailing list archive)
State Superseded
Headers show
Series libtracefs: Several updates | expand

Commit Message

Steven Rostedt Dec. 28, 2023, 8:35 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

On remount, the tracing directory may move, and the tracing_dir needs to be
updated. If tracing_dir is the same it is simply returned, but if it is not,
it has to be calculated again. This was fixed but if it was changed, the old
tracing_dir was never freed.

Always free the tracing_dir before calculating a new one. This also requires
changing the type by removing the "const" attribute.

Fixes: 92c9292a ("libtracefs: Have tracefs_{tracing,debug}_dir() make sure it's still mounted")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/tracefs-utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/tracefs-utils.c b/src/tracefs-utils.c
index ef90677cf617..e67b698f5b99 100644
--- a/src/tracefs-utils.c
+++ b/src/tracefs-utils.c
@@ -248,7 +248,7 @@  static int test_dir(const char *dir, const char *file)
  */
 const char *tracefs_tracing_dir(void)
 {
-	static const char *tracing_dir;
+	static char *tracing_dir;
 
 	/* Do not check custom_tracing_dir */
 	if (custom_tracing_dir)
@@ -257,6 +257,7 @@  const char *tracefs_tracing_dir(void)
 	if (tracing_dir && test_dir(tracing_dir, "trace"))
 		return tracing_dir;
 
+	free(tracing_dir);
 	tracing_dir = find_tracing_dir(false, true);
 	return tracing_dir;
 }