libubus: preserve the received message buffer for incoming invoke calls
Set ctx->msgbuf.data to NULL during the call. If ctx->msgbuf is needed during the call, a new buffer will be allocated. If not, ctx->msgbuf.data is restored to the previous value afterwards Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
parent
6a285141d9
commit
9562291f68
1 changed files with 14 additions and 0 deletions
|
@ -99,6 +99,7 @@ void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_
|
||||||
struct blob_attr **attrbuf;
|
struct blob_attr **attrbuf;
|
||||||
struct ubus_object *obj;
|
struct ubus_object *obj;
|
||||||
uint32_t objid;
|
uint32_t objid;
|
||||||
|
void *prev_data = NULL;
|
||||||
|
|
||||||
attrbuf = ubus_parse_msg(buf->data);
|
attrbuf = ubus_parse_msg(buf->data);
|
||||||
if (!attrbuf[UBUS_ATTR_OBJID])
|
if (!attrbuf[UBUS_ATTR_OBJID])
|
||||||
|
@ -120,7 +121,20 @@ void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (buf == &ctx->msgbuf) {
|
||||||
|
prev_data = buf->data;
|
||||||
|
buf->data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
cb(ctx, hdr, obj, attrbuf);
|
cb(ctx, hdr, obj, attrbuf);
|
||||||
|
|
||||||
|
if (prev_data) {
|
||||||
|
if (buf->data)
|
||||||
|
free(prev_data);
|
||||||
|
else
|
||||||
|
buf->data = prev_data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ubus_add_object_cb(struct ubus_request *req, int type, struct blob_attr *msg)
|
static void ubus_add_object_cb(struct ubus_request *req, int type, struct blob_attr *msg)
|
||||||
|
|
Loading…
Add table
Reference in a new issue