[OpenWrt-Devel] [PATCH] libubus: add null for ubus_context object in ubus_shutdown()

Alexandru Ardelean ardeleanalex at gmail.com
Thu Dec 17 03:45:22 EST 2015


At the moment, we do our own null checks before calling ubus_free().
The likely-hood of 'ctx' being null (in ubus_free()) is low, 
but since free() handles null, might make sense for ubus_free() to do so as well.

Signed-off-by: Alexandru Ardelean <ardeleanalex at gmail.com>
---
 libubus.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libubus.c b/libubus.c
index ccaa069..88a6ad3 100644
--- a/libubus.c
+++ b/libubus.c
@@ -354,6 +354,8 @@ struct ubus_context *ubus_connect(const char *path)
 void ubus_shutdown(struct ubus_context *ctx)
 {
 	blob_buf_free(&b);
+	if (!ctx)
+		return;
 	close(ctx->sock.fd);
 	free(ctx->msgbuf.data);
 }
-- 
2.1.4
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list