blobmsg_json: fix a memleak on error
authorFelix Fietkau <nbd@openwrt.org>
Sat, 12 Apr 2014 18:23:23 +0000 (20:23 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 12 Apr 2014 18:23:23 +0000 (20:23 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
blobmsg_json.c

index c84fd93df47d5cdb572d6caf5ecfee5cefadf651..3b32b932528ad1f6cfd9b97d5ad3b63d566de260 100644 (file)
@@ -304,8 +304,10 @@ char *blobmsg_format_json_with_cb(struct blob_attr *attr, bool list, blobmsg_jso
        else
                blobmsg_format_element(&s, attr, false, false);
 
-       if (!s.len)
+       if (!s.len) {
+               free(s.buf);
                return NULL;
+       }
 
        s.buf = realloc(s.buf, s.pos + 1);
        s.buf[s.pos] = 0;