Skip to content

Commit b796162

Browse files
tzstoyanovacmel
authored andcommitted
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.com Suggested-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> Acked-by: Namhyung 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.org Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7db6330 commit b796162

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎tools/lib/traceevent/event-plugin.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,23 +361,25 @@ int tep_plugin_add_option(const char *name, const char *val)
361361
if (!op) {
362362
op = malloc(sizeof(*op));
363363
if (!op)
364-
return -ENOMEM;
364+
goto out_free;
365365
memset(op, 0, sizeof(*op));
366-
op->next = trace_plugin_options;
367-
trace_plugin_options = op;
368-
369366
op->plugin = plugin;
370367
op->option = option_str;
371-
372368
if (val) {
373369
op->value = strdup(val);
374-
if (!op->value)
370+
if (!op->value) {
371+
free(op);
375372
goto out_free;
373+
}
376374
}
375+
op->next = trace_plugin_options;
376+
trace_plugin_options = op;
377377
}
378378

379379
return process_option(plugin, option_str, val);
380-
out_free:
380+
381+
out_free:
382+
free(plugin);
381383
free(option_str);
382384
return -ENOMEM;
383385
}

0 commit comments

Comments
 (0)