ubus: Fix issues reported by static code analysis tool Klocwork
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
This commit is contained in:
parent
2d660c519d
commit
7798d56301
6 changed files with 35 additions and 6 deletions
|
@ -106,8 +106,10 @@ static void test_count(struct uloop_timeout *timeout)
|
|||
count_to += count_progression;
|
||||
|
||||
s = count_to_number(count_to);
|
||||
if (!s)
|
||||
if (!s) {
|
||||
fprintf(stderr, "Could not allocate memory to count up to '%u'\n", count_to);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Sending count up to '%u'; string has length '%u'\n",
|
||||
count_to, (uint32_t)strlen(s));
|
||||
|
|
|
@ -93,6 +93,9 @@ static int test_hello(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
msgstr = blobmsg_data(tb[HELLO_MSG]);
|
||||
|
||||
hreq = calloc(1, sizeof(*hreq) + strlen(format) + strlen(obj->name) + strlen(msgstr) + 1);
|
||||
if (!hreq)
|
||||
return UBUS_STATUS_UNKNOWN_ERROR;
|
||||
|
||||
sprintf(hreq->data, format, obj->name, msgstr);
|
||||
ubus_defer_request(ctx, req, &hreq->req);
|
||||
hreq->timeout.cb = test_hello_reply;
|
||||
|
|
17
lua/ubus.c
17
lua/ubus.c
|
@ -382,6 +382,9 @@ static int ubus_lua_load_methods(lua_State *L, struct ubus_method *m)
|
|||
|
||||
/* setup the policy pointers */
|
||||
p = malloc(sizeof(struct blobmsg_policy) * plen);
|
||||
if (!p)
|
||||
return 1;
|
||||
|
||||
memset(p, 0, sizeof(struct blobmsg_policy) * plen);
|
||||
m->policy = p;
|
||||
lua_pushnil(L);
|
||||
|
@ -417,6 +420,9 @@ static struct ubus_object* ubus_lua_load_object(lua_State *L)
|
|||
|
||||
/* setup object pointers */
|
||||
obj = malloc(sizeof(struct ubus_lua_object));
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
memset(obj, 0, sizeof(struct ubus_lua_object));
|
||||
obj->o.name = lua_tostring(L, -2);
|
||||
|
||||
|
@ -427,6 +433,11 @@ static struct ubus_object* ubus_lua_load_object(lua_State *L)
|
|||
|
||||
/* setup type pointers */
|
||||
obj->o.type = malloc(sizeof(struct ubus_object_type));
|
||||
if (!obj->o.type) {
|
||||
free(obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(obj->o.type, 0, sizeof(struct ubus_object_type));
|
||||
obj->o.type->name = lua_tostring(L, -2);
|
||||
obj->o.type->id = 0;
|
||||
|
@ -529,9 +540,10 @@ ubus_lua_call_cb(struct ubus_request *req, int type, struct blob_attr *msg)
|
|||
{
|
||||
lua_State *L = (lua_State *)req->priv;
|
||||
|
||||
if (!msg)
|
||||
if (!msg && L)
|
||||
lua_pushnil(L);
|
||||
|
||||
if (msg && L)
|
||||
ubus_lua_parse_blob_array(L, blob_data(msg), blob_len(msg), true);
|
||||
}
|
||||
|
||||
|
@ -598,6 +610,9 @@ ubus_lua_load_event(lua_State *L)
|
|||
struct ubus_lua_event* event = NULL;
|
||||
|
||||
event = malloc(sizeof(struct ubus_lua_event));
|
||||
if (!event)
|
||||
return NULL;
|
||||
|
||||
memset(event, 0, sizeof(struct ubus_lua_event));
|
||||
event->e.cb = ubus_event_handler;
|
||||
|
||||
|
|
|
@ -267,6 +267,7 @@ void ubusd_event_init(void)
|
|||
{
|
||||
ubus_init_string_tree(&patterns, true);
|
||||
event_obj = ubusd_create_object_internal(NULL, UBUS_SYSTEM_OBJECT_EVENT);
|
||||
if (event_obj != NULL)
|
||||
event_obj->recv_msg = ubusd_event_recv;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,9 @@ static struct ubus_object_type *ubus_create_obj_type(struct blob_attr *sig)
|
|||
int rem;
|
||||
|
||||
type = calloc(1, sizeof(*type));
|
||||
if (!type)
|
||||
return NULL;
|
||||
|
||||
type->refcount = 1;
|
||||
|
||||
if (!ubus_alloc_id(&obj_types, &type->id, 0))
|
||||
|
|
|
@ -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,8 +503,10 @@ 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);
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue