trace: don't leak file descriptor in error path
authorDaniel Golle <daniel@makrotopia.org>
Sun, 5 Sep 2021 13:22:33 +0000 (14:22 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 15 Sep 2021 20:43:16 +0000 (21:43 +0100)
Coverity CID: 1491022 Resource leak
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
trace/trace.c

index 40cf3df5b9adc031bd04a34e2beec401728fee00..d895798e762e13af3cf90beee2590a706b302b6b 100644 (file)
@@ -163,8 +163,10 @@ static void print_syscalls(int policy, const char *json)
                FILE *fp = fopen(json, "w");
                if (fp) {
                        tmp = blobmsg_format_json_indent(b.head, true, 0);
-                       if (!tmp)
+                       if (!tmp) {
+                               fclose(fp);
                                return;
+                       }
 
                        fprintf(fp, "%s\n", tmp);
                        free(tmp);