From: "Tzvetomir Stoyanov (VMware)" <tz.stoya...@gmail.com>

Free allocated resources and return -1 in case strdup() fails in
tep_add_plugin_path() API.

Link: 
https://lore.kernel.org/r/cam9d7chfvjwodpvrhgc5e2j80perojmyv_fd8x3cpn9hfru...@mail.gmail.com
Link: 
https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-9-tz.stoya...@gmail.com
Link: 
https://lore.kernel.org/linux-trace-devel/20200716092014.2613403-9-tz.stoya...@gmail.com

Suggested-by: Namhyung Kim <namhy...@kernel.org>
Acked-by: Namhyung Kim <namhy...@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoya...@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rost...@goodmis.org>
---
 tools/lib/traceevent/event-plugin.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/lib/traceevent/event-plugin.c 
b/tools/lib/traceevent/event-plugin.c
index f0877a7e3e8d..e7c2acb8680f 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -665,6 +665,10 @@ int tep_add_plugin_path(struct tep_handle *tep, char *path,
                return -1;
 
        dir->path = strdup(path);
+       if (!dir->path) {
+               free(dir);
+               return -1;
+       }
        dir->prio = prio;
        dir->next = tep->plugins_dir;
        tep->plugins_dir = dir;
-- 
2.26.2


Reply via email to