hotplug: fix memleak in debug codepath
authorFelix Fietkau <nbd@openwrt.org>
Sun, 25 May 2014 18:48:09 +0000 (20:48 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 25 May 2014 18:48:09 +0000 (20:48 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
plug/hotplug.c

index ca1e823b65c5fdeac1c5d30f2633669abb2e5a56..07abaf8ac8b651d960b23587d42a6b9b48f3d16c 100644 (file)
@@ -399,6 +399,18 @@ static struct json_script_ctx jctx = {
        .handle_file = rule_handle_file,
 };
 
+static void hotplug_handler_debug(struct blob_attr *data)
+{
+       char *str;
+
+       if (debug < 3)
+               return;
+
+       str = blobmsg_format_json(data, true);
+       DEBUG(3, "%s\n", str);
+       free(str);
+}
+
 static void hotplug_handler(struct uloop_fd *u, unsigned int ev)
 {
        int i = 0;
@@ -421,7 +433,7 @@ static void hotplug_handler(struct uloop_fd *u, unsigned int ev)
                i += l;
        }
        blobmsg_close_table(&b, index);
-       DEBUG(3, "%s\n", blobmsg_format_json(b.head, true));
+       hotplug_handler_debug(b.head);
        json_script_run(&jctx, rule_file, blob_data(b.head));
 }