uxc: free string returned by blobmsg_format_json_indent()
authorDaniel Golle <daniel@makrotopia.org>
Mon, 23 Aug 2021 17:04:55 +0000 (18:04 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 24 Aug 2021 17:31:51 +0000 (18:31 +0100)
Coverity ID: 1490068 Resource leak

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
uxc.c

diff --git a/uxc.c b/uxc.c
index 722176370de7ea0e8ef808520581471da28e4019..3af4fa99bfcd87508753137aa7b23bfee71b8b42 100644 (file)
--- a/uxc.c
+++ b/uxc.c
@@ -361,6 +361,7 @@ static int uxc_state(char *name)
        char *bundle = NULL;
        char *jail_name = NULL;
        char *state = NULL;
+       char *tmp;
        static struct blob_buf buf;
 
        if (s)
@@ -401,7 +402,15 @@ static int uxc_state(char *name)
        blobmsg_add_string(&buf, "status", s?"stopped":"uninitialized");
        blobmsg_add_string(&buf, "bundle", bundle);
 
-       printf("%s\n", blobmsg_format_json_indent(buf.head, true, 0));
+       tmp = blobmsg_format_json_indent(buf.head, true, 0);
+       if (!tmp) {
+               blob_buf_free(&buf);
+               return ENOMEM;
+       }
+
+       printf("%s\n", tmp);
+       free(tmp);
+
        blob_buf_free(&buf);
 
        return 0;