Blame libtracefs-Prevent-a-memory-leak-in-tracefs_synth_ad.patch

Jerome Marchand 3772ca
From 2342293f9aac9ce3706eb7ffaab0e5cf11231215 Mon Sep 17 00:00:00 2001
Jerome Marchand 3772ca
From: Jerome Marchand <jmarchan@redhat.com>
Jerome Marchand 3772ca
Date: Thu, 6 Jun 2024 17:38:18 +0200
Jerome Marchand 3772ca
Subject: [PATCH 04/15] libtracefs: Prevent a memory leak in
Jerome Marchand 3772ca
 tracefs_synth_add_end_field()
Jerome Marchand 3772ca
Jerome Marchand 3772ca
Free tmp_var in the error path.
Jerome Marchand 3772ca
Jerome Marchand 3772ca
Fixes a RESSOURCE_LEAK error (CWE-772)
Jerome Marchand 3772ca
Jerome Marchand 3772ca
Link: https://lore.kernel.org/linux-trace-devel/20240606153830.2666120-5-jmarchan@redhat.com
Jerome Marchand 3772ca
Jerome Marchand 3772ca
Fixes: f1cdbe9b52b07 ("libtracefs: Have end event variables not be the end event field name")
Jerome Marchand 3772ca
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Jerome Marchand 3772ca
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Jerome Marchand 3772ca
---
Jerome Marchand 3772ca
 src/tracefs-hist.c | 6 +++---
Jerome Marchand 3772ca
 1 file changed, 3 insertions(+), 3 deletions(-)
Jerome Marchand 3772ca
Jerome Marchand 3772ca
diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
Jerome Marchand 3772ca
index 87287b5..4f4971e 100644
Jerome Marchand 3772ca
--- a/src/tracefs-hist.c
Jerome Marchand 3772ca
+++ b/src/tracefs-hist.c
Jerome Marchand 3772ca
@@ -1576,7 +1576,7 @@ int tracefs_synth_add_end_field(struct tracefs_synth *synth,
Jerome Marchand 3772ca
 	const struct tep_format_field *field;
Jerome Marchand 3772ca
 	const char *hname = NULL;
Jerome Marchand 3772ca
 	char *tmp_var = NULL;
Jerome Marchand 3772ca
-	int ret;
Jerome Marchand 3772ca
+	int ret = -1;
Jerome Marchand 3772ca
 
Jerome Marchand 3772ca
 	if (!synth || !end_field) {
Jerome Marchand 3772ca
 		errno = EINVAL;
Jerome Marchand 3772ca
@@ -1594,15 +1594,15 @@ int tracefs_synth_add_end_field(struct tracefs_synth *synth,
Jerome Marchand 3772ca
 		tmp_var = new_arg(synth);
Jerome Marchand 3772ca
 
Jerome Marchand 3772ca
 	if (!trace_verify_event_field(synth->end_event, end_field, &field))
Jerome Marchand 3772ca
-		return -1;
Jerome Marchand 3772ca
+		goto out;
Jerome Marchand 3772ca
 
Jerome Marchand 3772ca
 	ret = add_var(&synth->end_vars, name ? hname : tmp_var, end_field, false);
Jerome Marchand 3772ca
 	if (ret)
Jerome Marchand 3772ca
 		goto out;
Jerome Marchand 3772ca
 
Jerome Marchand 3772ca
 	ret = add_synth_fields(synth, field, name, hname ? : tmp_var);
Jerome Marchand 3772ca
-	free(tmp_var);
Jerome Marchand 3772ca
  out:
Jerome Marchand 3772ca
+	free(tmp_var);
Jerome Marchand 3772ca
 	return ret;
Jerome Marchand 3772ca
 }
Jerome Marchand 3772ca
 
Jerome Marchand 3772ca
-- 
Jerome Marchand 3772ca
2.45.2
Jerome Marchand 3772ca