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/[email protected] Link: https://lore.kernel.org/linux-trace-devel/[email protected] Suggested-by: Namhyung Kim <[email protected]> Signed-off-by: Tzvetomir Stoyanov (VMware) <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7db6330 commit b796162

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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)