trace: free memory allocated by blobmsg_format_json_indent()
authorDaniel Golle <daniel@makrotopia.org>
Mon, 30 Aug 2021 19:20:49 +0000 (20:20 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 30 Aug 2021 19:30:43 +0000 (20:30 +0100)
Only one out of two occurances have been addressed previously.
Close the other one now.

Coverity CID: 1446205
Fixes: 51f1cd23 ("trace: free string returned by blobmsg_format_json_indent()")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
trace/trace.c

index 8d90b5ee7fa5e03c99e02e917edb82e15e7f94d0..87a98a632b5e42eb041357dce417022239006282 100644 (file)
@@ -162,7 +162,12 @@ static void print_syscalls(int policy, const char *json)
        if (json) {
                FILE *fp = fopen(json, "w");
                if (fp) {
-                       fprintf(fp, "%s\n", blobmsg_format_json_indent(b.head, true, 0));
+                       tmp = blobmsg_format_json_indent(b.head, true, 0);
+                       if (!tmp)
+                               return;
+
+                       free(tmp);
+                       fprintf(fp, "%s\n", tmp);
                        fclose(fp);
                        ULOG_INFO("saving syscall trace to %s\n", json);
                } else {
@@ -176,7 +181,6 @@ static void print_syscalls(int policy, const char *json)
                printf("%s\n", tmp);
                free(tmp);
        }
-
 }
 
 static void report_seccomp_vialation(pid_t pid, unsigned syscall)