ubusd: fix id lookup of objects with path and no methods
[project/ubus.git] / libubus.c
index bfbaeb6..8163ff7 100644 (file)
--- a/libubus.c
+++ b/libubus.c
@@ -294,6 +294,7 @@ int ubus_connect_ctx(struct ubus_context *ctx, const char *path)
        avl_init(&ctx->objects, ubus_cmp_id, false, NULL);
        if (ubus_reconnect(ctx, path)) {
                free(ctx->msgbuf.data);
+               ctx->msgbuf.data = NULL;
                return -1;
        }
 
@@ -358,6 +359,8 @@ struct ubus_context *ubus_connect(const char *path)
 void ubus_shutdown(struct ubus_context *ctx)
 {
        blob_buf_free(&b);
+       if (!ctx)
+               return;
        close(ctx->sock.fd);
        free(ctx->msgbuf.data);
 }