summaryrefslogtreecommitdiff
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2026-06-15 20:35:55 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-08-31 09:05:26 -0300
commitbfde6848c1e24fd979d0138c57c1cc28c35093c3 (patch)
treecc2cbe4fd63881b150a24aadbd34c3896f709fcf /tools/perf
parent0155f05ea6e133c18a04b8b5945cac59870da156 (diff)
downloadlinux-next-bfde6848c1e24fd979d0138c57c1cc28c35093c3.tar.gz
linux-next-bfde6848c1e24fd979d0138c57c1cc28c35093c3.zip
perf jitdump: Fix funlockfile on unlocked stream in jit_open() error path
If the malloc() for the initial read buffer fails, jit_open() jumps to the error label which calls funlockfile(jd->in). However, flockfile() is called later in the function, so at this point the stream was never locked. Calling funlockfile() on an unlocked stream is undefined behavior per POSIX. Split the error path into two labels: 'error' (after flockfile) calls funlockfile before cleanup, 'error_noflock' (before flockfile) skips the unlock. Fixes: 9b07e27f88b9 ("perf inject: Add jitdump mmap injection support") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Reviewed-by: Ian Rogers <irogers@google.com> Cc: Stephane Eranian <eranian@google.com> Assisted-by: LLM Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/jitdump.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 45f0e21b0e78..ae63366b86c6 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -157,7 +157,7 @@ jit_open(struct jit_buf_desc *jd, const char *name)
buf = malloc(bsz);
if (!buf)
- goto error;
+ goto error_noflock;
/*
* protect from writer modifying the file while we are reading it
@@ -246,8 +246,9 @@ jit_open(struct jit_buf_desc *jd, const char *name)
return 0;
error:
- free(buf);
funlockfile(jd->in);
+error_noflock:
+ free(buf);
fclose(jd->in);
return retval;
}