summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEyal Birger <eyal.birger@gmail.com>2016-05-15 08:13:27 +0300
committerFelix Fietkau <nbd@nbd.name>2016-05-15 09:39:24 +0200
commit3b8d4b5653ef47bd2032d377cecfee40b613eb72 (patch)
tree2a73bf8570eb9959b1112364c2774af22dba1832
parentfcf5d8af65f41d6a106ad08d1df5de9729f5399a (diff)
downloadubus-3b8d4b5653ef47bd2032d377cecfee40b613eb72.tar.gz
libubus: nullify stale msgbuf pointer in case of ubus_connect_ctx() failure
If the ubus_reconnect() call fails in ubus_connect_ctx(), the msgbuf.data newly allocated buffer is freed, but its pointer in the ubus_context is not removed. This leads to a double free error if ubus_auto_shutdown() is called for cleanup after ubus_auto_connect() failed to connect to ubusd. Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
-rw-r--r--libubus.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/libubus.c b/libubus.c
index d52faff..8163ff7 100644
--- 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;
}