mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:17:34 +00:00
LibC: Fix memory leak in realpath
This commit is contained in:
parent
2a8baf9582
commit
ed857bc06e
1 changed files with 6 additions and 1 deletions
|
@ -1049,11 +1049,16 @@ char* realpath(const char* pathname, char* buffer)
|
|||
return nullptr;
|
||||
}
|
||||
size_t size = PATH_MAX;
|
||||
if (buffer == nullptr)
|
||||
bool self_allocated = false;
|
||||
if (buffer == nullptr) {
|
||||
buffer = (char*)malloc(size);
|
||||
self_allocated = true;
|
||||
}
|
||||
Syscall::SC_realpath_params params { { pathname, strlen(pathname) }, { buffer, size } };
|
||||
int rc = syscall(SC_realpath, ¶ms);
|
||||
if (rc < 0) {
|
||||
if (self_allocated)
|
||||
free(buffer);
|
||||
errno = -rc;
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue