mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
size_t size = PATH_MAX;
|
size_t size = PATH_MAX;
|
||||||
if (buffer == nullptr)
|
bool self_allocated = false;
|
||||||
|
if (buffer == nullptr) {
|
||||||
buffer = (char*)malloc(size);
|
buffer = (char*)malloc(size);
|
||||||
|
self_allocated = true;
|
||||||
|
}
|
||||||
Syscall::SC_realpath_params params { { pathname, strlen(pathname) }, { buffer, size } };
|
Syscall::SC_realpath_params params { { pathname, strlen(pathname) }, { buffer, size } };
|
||||||
int rc = syscall(SC_realpath, ¶ms);
|
int rc = syscall(SC_realpath, ¶ms);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
if (self_allocated)
|
||||||
|
free(buffer);
|
||||||
errno = -rc;
|
errno = -rc;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue