plugin: exec: properly free memory on parse error
authorYousong Zhou <yszhou4tech@gmail.com>
Mon, 21 Oct 2019 06:10:26 +0000 (06:10 +0000)
committerJo-Philipp Wich <jo@mein.io>
Tue, 29 Oct 2019 07:59:37 +0000 (08:59 +0100)
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
plugin.c

index fa5f09f932865a0ee1758c277eb95fdc1ef497c6..877345d7a9a635efb94f7e5e5ff223731c274176 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -321,11 +321,16 @@ rpc_plugin_parse_exec(const char *name, int fd)
 
        obj_type = calloc(1, sizeof(*obj_type));
 
-       if (!obj_type)
+       if (!obj_type) {
+               free(obj);
                return NULL;
+       }
 
-       if (asprintf((char **)&obj_type->name, "luci-rpc-plugin-%s", name) < 0)
+       if (asprintf((char **)&obj_type->name, "luci-rpc-plugin-%s", name) < 0) {
+               free(obj);
+               free(obj_type);
                return NULL;
+       }
 
        obj_type->methods = methods;
        obj_type->n_methods = n_method;