diff options
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibC/unistd.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index b35f011289..718ff6961c 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -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); } |