[compiler-rt] Fixed small memory leak in libprofile (PR #141739)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 28 03:37:03 PDT 2025
https://github.com/gbMattN created https://github.com/llvm/llvm-project/pull/141739
Inside `getCurFilename`, there is this code snippit
```
if (!lprofCurFilename.FilenamePat || !lprofCurFilename.FilenamePat[0])
return 0;
```
If this is true, we return `"\0"`, but would leak the memory in `FilenameBuf`.
This pull request adds a free before then to properly free the memory. There was already a check that we allocated memory, so there is no need to worry about freeing unallocated memory.
>From fb19a4ebd7313e322b2f87bba393abbbd1026ead Mon Sep 17 00:00:00 2001
From: gbMattN <matthew.nagy at sony.com>
Date: Wed, 28 May 2025 11:33:16 +0100
Subject: [PATCH] Fixed small memory leak in libprofile
---
compiler-rt/lib/profile/InstrProfilingFile.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index e6bab9533146b..354f21b786151 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -1088,8 +1088,10 @@ const char *__llvm_profile_get_filename(void) {
return "\0";
}
Filename = getCurFilename(FilenameBuf, 1);
- if (!Filename)
+ if (!Filename) {
+ free(FilenameBuf);
return "\0";
+ }
return FilenameBuf;
}
More information about the llvm-commits
mailing list