Browse Source

Fix memory leak in `os.get_current_directory` on failure on *nix systems

gingerBill 2 years ago
parent
commit
b6ca10cd5e
4 changed files with 4 additions and 0 deletions
  1. 1 0
      core/os/os_darwin.odin
  2. 1 0
      core/os/os_freebsd.odin
  3. 1 0
      core/os/os_linux.odin
  4. 1 0
      core/os/os_openbsd.odin

+ 1 - 0
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)

+ 1 - 0
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)

+ 1 - 0
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)

+ 1 - 0
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)