[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211209024317.11783-1-linmq006@gmail.com>
Date: Thu, 9 Dec 2021 02:43:17 +0000
From: Miaoqian Lin <linmq006@...il.com>
To: rostedt@...dmis.org
Cc: linmq006@...il.com, linux-kernel@...r.kernel.org, mingo@...hat.com
Subject: [PATCH v2] tracing: Fix possible memory leak in __create_synth_event
Before goto err, call argv_free to handle argv in order to prevent
memory leak.
Signed-off-by: Miaoqian Lin <linmq006@...il.com>
Suggested-by: Steven Rostedt (VMware) <rostedt@...dmis.org>
---
Changes in v2:
use a cleaner way to handle cleanup operations
---
---
kernel/trace/trace_events_synth.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index 22db3ce95e74..c4a490ec7a38 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -1262,26 +1262,26 @@ static int __create_synth_event(const char *name, const char *raw_fields)
if (cmd_version > 1 && n_fields_this_loop >= 1) {
synth_err(SYNTH_ERR_INVALID_CMD, errpos(field_str));
ret = -EINVAL;
- goto err;
+ goto err_free_arg;
}
fields[n_fields++] = field;
if (n_fields == SYNTH_FIELDS_MAX) {
synth_err(SYNTH_ERR_TOO_MANY_FIELDS, 0);
ret = -EINVAL;
- goto err;
+ goto err_free_arg;
}
n_fields_this_loop++;
}
+ argv_free(argv);
if (consumed < argc) {
synth_err(SYNTH_ERR_INVALID_CMD, 0);
ret = -EINVAL;
goto err;
}
- argv_free(argv);
}
if (n_fields == 0) {
@@ -1307,6 +1307,8 @@ static int __create_synth_event(const char *name, const char *raw_fields)
kfree(saved_fields);
return ret;
+ err_free_arg:
+ argv_free(argv);
err:
for (i = 0; i < n_fields; i++)
free_synth_field(fields[i]);
--
2.17.1
Powered by blists - more mailing lists