ubusd: fix sending remove-object notification
[project/ubus.git] / ubusd_proto.c
index 09faeb2..53e507a 100644 (file)
@@ -130,8 +130,8 @@ static int ubusd_handle_remove_object(struct ubus_client *cl, struct ubus_msg_bu
        if (obj->type && obj->type->refcount == 1)
                blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id);
 
-       ubusd_free_object(obj);
        ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA);
+       ubusd_free_object(obj);
 
        return 0;
 }
@@ -146,7 +146,7 @@ static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf *
 
        blob_buf_init(&b, 0);
        blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id);
-       if (attr[UBUS_ATTR_SIGNATURE])
+       if (attr[UBUS_ATTR_SIGNATURE] && obj->type)
                blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id);
 
        ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA);
@@ -159,6 +159,9 @@ static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, stru
        int cnt = 0;
        void *s;
 
+       if (!obj->type)
+               return;
+
        blob_buf_init(&b, 0);
 
        blob_put_string(&b, UBUS_ATTR_OBJPATH, obj->path.key);
@@ -257,7 +260,7 @@ static int ubusd_handle_invoke(struct ubus_client *cl, struct ubus_msg_buf *ub,
        method = blob_data(attr[UBUS_ATTR_METHOD]);
 
        if (ubusd_acl_check(cl, obj->path.key, method, UBUS_ACL_ACCESS))
-               return UBUS_STATUS_NOT_FOUND;
+               return UBUS_STATUS_PERMISSION_DENIED;
 
        if (!obj->client)
                return obj->recv_msg(cl, ub, method, attr[UBUS_ATTR_DATA]);
@@ -500,6 +503,7 @@ void ubusd_proto_free_client(struct ubus_client *cl)
                ubusd_free_object(obj);
        }
 
+       ubusd_acl_free_client(cl);
        ubus_free_id(&clients, &cl->id);
 }