Commit c24be24a authored by Miaoqian Lin's avatar Miaoqian Lin Committed by Steven Rostedt (VMware)

tracing: Fix possible memory leak in __create_synth_event() error path

There's error paths in __create_synth_event() after the argv is allocated
that fail to free it. Add a jump to free it when necessary.

Link: https://lkml.kernel.org/r/20211209024317.11783-1-linmq006@gmail.comSuggested-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
[ Fixed up the patch and change log ]
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent e1067a07
...@@ -1237,9 +1237,8 @@ static int __create_synth_event(const char *name, const char *raw_fields) ...@@ -1237,9 +1237,8 @@ static int __create_synth_event(const char *name, const char *raw_fields)
argv + consumed, &consumed, argv + consumed, &consumed,
&field_version); &field_version);
if (IS_ERR(field)) { if (IS_ERR(field)) {
argv_free(argv);
ret = PTR_ERR(field); ret = PTR_ERR(field);
goto err; goto err_free_arg;
} }
/* /*
...@@ -1262,18 +1261,19 @@ static int __create_synth_event(const char *name, const char *raw_fields) ...@@ -1262,18 +1261,19 @@ static int __create_synth_event(const char *name, const char *raw_fields)
if (cmd_version > 1 && n_fields_this_loop >= 1) { if (cmd_version > 1 && n_fields_this_loop >= 1) {
synth_err(SYNTH_ERR_INVALID_CMD, errpos(field_str)); synth_err(SYNTH_ERR_INVALID_CMD, errpos(field_str));
ret = -EINVAL; ret = -EINVAL;
goto err; goto err_free_arg;
} }
fields[n_fields++] = field; fields[n_fields++] = field;
if (n_fields == SYNTH_FIELDS_MAX) { if (n_fields == SYNTH_FIELDS_MAX) {
synth_err(SYNTH_ERR_TOO_MANY_FIELDS, 0); synth_err(SYNTH_ERR_TOO_MANY_FIELDS, 0);
ret = -EINVAL; ret = -EINVAL;
goto err; goto err_free_arg;
} }
n_fields_this_loop++; n_fields_this_loop++;
} }
argv_free(argv);
if (consumed < argc) { if (consumed < argc) {
synth_err(SYNTH_ERR_INVALID_CMD, 0); synth_err(SYNTH_ERR_INVALID_CMD, 0);
...@@ -1281,7 +1281,6 @@ static int __create_synth_event(const char *name, const char *raw_fields) ...@@ -1281,7 +1281,6 @@ static int __create_synth_event(const char *name, const char *raw_fields)
goto err; goto err;
} }
argv_free(argv);
} }
if (n_fields == 0) { if (n_fields == 0) {
...@@ -1307,6 +1306,8 @@ static int __create_synth_event(const char *name, const char *raw_fields) ...@@ -1307,6 +1306,8 @@ static int __create_synth_event(const char *name, const char *raw_fields)
kfree(saved_fields); kfree(saved_fields);
return ret; return ret;
err_free_arg:
argv_free(argv);
err: err:
for (i = 0; i < n_fields; i++) for (i = 0; i < n_fields; i++)
free_synth_field(fields[i]); free_synth_field(fields[i]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment