提交 b796162b 编写于 作者: T Tzvetomir Stoyanov (VMware) 提交者: Arnaldo Carvalho de Melo

libtraceevent: Improve error handling of tep_plugin_add_option() API

In case of memory error, ensure all allocated resources are freed.
Do not append broken option in trace_plugin_options list.

Link: https://lore.kernel.org/r/CAM9d7cizjF+fbK7YzmsBDgrx__4YAOsmEq67D3sWET8FF+YdFA@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-5-tz.stoyanov@gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200716092014.2613403-5-tz.stoyanov@gmail.comSuggested-by: NNamhyung Kim <namhyung@kernel.org>
Signed-off-by: NTzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Acked-by: NNamhyung Kim <namhyung@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lore.kernel.org/lkml/20200722011755.158091410@goodmis.orgSigned-off-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 7db6330d
......@@ -361,23 +361,25 @@ int tep_plugin_add_option(const char *name, const char *val)
if (!op) {
op = malloc(sizeof(*op));
if (!op)
return -ENOMEM;
goto out_free;
memset(op, 0, sizeof(*op));
op->next = trace_plugin_options;
trace_plugin_options = op;
op->plugin = plugin;
op->option = option_str;
if (val) {
op->value = strdup(val);
if (!op->value)
if (!op->value) {
free(op);
goto out_free;
}
}
op->next = trace_plugin_options;
trace_plugin_options = op;
}
return process_option(plugin, option_str, val);
out_free:
out_free:
free(plugin);
free(option_str);
return -ENOMEM;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册