Skip to content

Commit aa07c9f

Browse files
gbMattNsivan-shani
authored andcommitted
Fixed small memory leak in libprofile (llvm#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.
1 parent 3492d8a commit aa07c9f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compiler-rt/lib/profile/InstrProfilingFile.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,10 @@ const char *__llvm_profile_get_filename(void) {
10881088
return "\0";
10891089
}
10901090
Filename = getCurFilename(FilenameBuf, 1);
1091-
if (!Filename)
1091+
if (!Filename) {
1092+
free(FilenameBuf);
10921093
return "\0";
1094+
}
10931095

10941096
return FilenameBuf;
10951097
}

0 commit comments

Comments
 (0)