trace: fix potential use-after-free occurence
authorNick Hainke <vincent@systemli.org>
Mon, 30 Aug 2021 20:37:10 +0000 (22:37 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 30 Aug 2021 21:15:10 +0000 (22:15 +0100)
char* tmp is used in the fprintf function altough it is already freed.

Fixes: e5b38fd1 ("trace: free memory allocated by blobmsg_format_json_indent()")
Signed-off-by: Nick Hainke <vincent@systemli.org>
trace/trace.c

index 87a98a632b5e42eb041357dce417022239006282..40cf3df5b9adc031bd04a34e2beec401728fee00 100644 (file)
@@ -166,8 +166,8 @@ static void print_syscalls(int policy, const char *json)
                        if (!tmp)
                                return;
 
-                       free(tmp);
                        fprintf(fp, "%s\n", tmp);
+                       free(tmp);
                        fclose(fp);
                        ULOG_INFO("saving syscall trace to %s\n", json);
                } else {