uci: fix memory leak in rpc_uci_replace_savedir()
[project/rpcd.git] / plugin.c
index 687944d..532fa15 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -108,12 +108,9 @@ rpc_plugin_call_finish_cb(struct blob_buf *blob, int stat, void *priv)
        {
                if (c->obj)
                {
-                       if (json_object_get_type(c->obj) == json_type_object ||
-                           json_object_get_type(c->obj) == json_type_array)
-                       {
-                               blobmsg_add_json_element(blob, NULL, c->obj);
+                       if (json_object_get_type(c->obj) == json_type_object &&
+                           blobmsg_add_object(blob, c->obj))
                                rv = UBUS_STATUS_OK;
-                       }
 
                        json_object_put(c->obj);
                }
@@ -327,7 +324,9 @@ rpc_plugin_parse_exec(const char *name, int fd)
        if (!obj_type)
                return NULL;
 
-       asprintf((char **)&obj_type->name, "luci-rpc-plugin-%s", name);
+       if (asprintf((char **)&obj_type->name, "luci-rpc-plugin-%s", name) < 0)
+               return NULL;
+
        obj_type->methods = methods;
        obj_type->n_methods = n_method;
 
@@ -413,7 +412,7 @@ rpc_plugin_register_library(struct ubus_context *ctx, const char *path)
        struct rpc_plugin *p;
        void *dlh;
 
-       dlh = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
+       dlh = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
 
        if (!dlh)
                return UBUS_STATUS_UNKNOWN_ERROR;