ubus: Fix issues reported by static code analysis tool Klocwork
[project/ubus.git] / ubusd_proto.c
index 811aa79..991a70a 100644 (file)
@@ -165,7 +165,7 @@ static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, stru
 
        s = blob_nest_start(&b, UBUS_ATTR_SIGNATURE);
        list_for_each_entry(m, &obj->type->methods, list)
-               blob_put(&b, blob_id(m->data), blob_data(m->data), blob_len(m->data));
+               blobmsg_add_blob(&b, m->data);
        blob_nest_end(&b, s);
 
        ubus_send_msg_from_blob(cl, ub, UBUS_MSG_DATA);
@@ -487,6 +487,9 @@ void ubus_notify_subscription(struct ubus_object *obj)
        blob_put_int8(&b, UBUS_ATTR_ACTIVE, active);
 
        ub = ubus_msg_from_blob(false);
+       if (!ub)
+               return;
+
        ubus_msg_init(ub, UBUS_MSG_NOTIFY, ++obj->invoke_seq, 0);
        ubus_msg_send(obj->client, ub, true);
 }
@@ -500,13 +503,15 @@ void ubus_notify_unsubscribe(struct ubus_subscription *s)
        blob_put_int32(&b, UBUS_ATTR_TARGET, s->target->id.id);
 
        ub = ubus_msg_from_blob(false);
-       ubus_msg_init(ub, UBUS_MSG_UNSUBSCRIBE, ++s->subscriber->invoke_seq, 0);
-       ubus_msg_send(s->subscriber->client, ub, true);
+       if (ub != NULL) {
+               ubus_msg_init(ub, UBUS_MSG_UNSUBSCRIBE, ++s->subscriber->invoke_seq, 0);
+               ubus_msg_send(s->subscriber->client, ub, true);
+       }
 
        ubus_unsubscribe(s);
 }
 
-static void __init ubusd_proto_init(void)
+static void __constructor ubusd_proto_init(void)
 {
        ubus_init_id_tree(&clients);