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

This commit is contained in:
gingerBill
2023-01-16 15:29:45 +00:00
parent 7416f72565
commit b6ca10cd5e
4 changed files with 4 additions and 0 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)