Fixed small memory leak in libprofile (#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.
This commit is contained in:
gbMattN 2025-05-28 14:51:50 +01:00 committed by GitHub
parent 0ebe5557d9
commit 2b1ebef8b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
}