aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-01-16 15:29:45 +0000
committergingerBill <bill@gingerbill.org>2023-01-16 15:29:45 +0000
commitb6ca10cd5eec06bc0f9d875cbff29d602fb01bf1 (patch)
treef476063d26f9fc1b95748edaa83666af40f307b6 /core
parent7416f72565c3b899da1c4914acb43ed92e574739 (diff)
Fix memory leak in `os.get_current_directory` on failure on *nix systems
Diffstat (limited to 'core')
-rw-r--r--core/os/os_darwin.odin1
-rw-r--r--core/os/os_freebsd.odin1
-rw-r--r--core/os/os_linux.odin1
-rw-r--r--core/os/os_openbsd.odin1
4 files changed, 4 insertions, 0 deletions
diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin
index 456ac1d76..2d8a871c1 100644
--- a/core/os/os_darwin.odin
+++ b/core/os/os_darwin.odin
@@ -701,6 +701,7 @@ get_current_directory :: proc() -> string {
return string(cwd)
}
if Errno(get_last_error()) != ERANGE {
+ delete(buf)
return ""
}
resize(&buf, len(buf)+page_size)
diff --git a/core/os/os_freebsd.odin b/core/os/os_freebsd.odin
index eacbae97a..0ab48efaf 100644
--- a/core/os/os_freebsd.odin
+++ b/core/os/os_freebsd.odin
@@ -651,6 +651,7 @@ get_current_directory :: proc() -> string {
return string(cwd)
}
if Errno(get_last_error()) != ERANGE {
+ delete(buf)
return ""
}
resize(&buf, len(buf)+page_size)
diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin
index 6f2196504..1a66f7704 100644
--- a/core/os/os_linux.odin
+++ b/core/os/os_linux.odin
@@ -823,6 +823,7 @@ get_current_directory :: proc() -> string {
return strings.string_from_nul_terminated_ptr(&buf[0], len(buf))
}
if _get_errno(res) != ERANGE {
+ delete(buf)
return ""
}
resize(&buf, len(buf)+page_size)
diff --git a/core/os/os_openbsd.odin b/core/os/os_openbsd.odin
index 3423c1692..75ad19c46 100644
--- a/core/os/os_openbsd.odin
+++ b/core/os/os_openbsd.odin
@@ -649,6 +649,7 @@ get_current_directory :: proc() -> string {
return string(cwd)
}
if Errno(get_last_error()) != ERANGE {
+ delete(buf)
return ""
}
resize(&buf, len(buf) + MAX_PATH)