mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +00:00
LibC: Fix memory leak in getcwd
This commit is contained in:
parent
ed857bc06e
commit
72ac97ef6a
1 changed files with 5 additions and 0 deletions
|
@ -322,11 +322,16 @@ int fchdir(int fd)
|
|||
|
||||
char* getcwd(char* buffer, size_t size)
|
||||
{
|
||||
bool self_allocated = false;
|
||||
if (!buffer) {
|
||||
size = size ? size : PATH_MAX;
|
||||
buffer = (char*)malloc(size);
|
||||
self_allocated = true;
|
||||
}
|
||||
int rc = syscall(SC_getcwd, buffer, size);
|
||||
if (rc < 0 && self_allocated) {
|
||||
free(buffer);
|
||||
}
|
||||
__RETURN_WITH_ERRNO(rc, buffer, nullptr);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue