mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00:00
LibC: Fix memory leak in getcwd
This commit is contained in:
parent
ed857bc06e
commit
72ac97ef6a
Notes:
sideshowbarker
2024-07-18 23:10:25 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/72ac97ef6ab Pull-request: https://github.com/SerenityOS/serenity/pull/4965 Reviewed-by: https://github.com/bugaevc Reviewed-by: https://github.com/emanuele6
|
@ -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…
Reference in a new issue