mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix possible leaks in os2.user_* calls
This commit is contained in:
+10
-6
@@ -4,21 +4,23 @@ import "base:runtime"
|
|||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
user_cache_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
user_cache_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||||
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
#partial switch ODIN_OS {
|
#partial switch ODIN_OS {
|
||||||
case .Windows:
|
case .Windows:
|
||||||
dir = get_env("LocalAppData", allocator)
|
dir = get_env("LocalAppData", temp_allocator())
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
dir = clone_string(dir, allocator) or_return
|
dir = clone_string(dir, allocator) or_return
|
||||||
}
|
}
|
||||||
case .Darwin:
|
case .Darwin:
|
||||||
dir = get_env("HOME", allocator)
|
dir = get_env("HOME", temp_allocator())
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
dir = concatenate({dir, "/Library/Caches"}, allocator) or_return
|
dir = concatenate({dir, "/Library/Caches"}, allocator) or_return
|
||||||
}
|
}
|
||||||
case: // All other UNIX systems
|
case: // All other UNIX systems
|
||||||
dir = get_env("XDG_CACHE_HOME", allocator)
|
dir = get_env("XDG_CACHE_HOME", allocator)
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
dir = get_env("HOME", allocator)
|
dir = get_env("HOME", temp_allocator())
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -33,21 +35,23 @@ user_cache_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error
|
|||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
user_config_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
user_config_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||||
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
#partial switch ODIN_OS {
|
#partial switch ODIN_OS {
|
||||||
case .Windows:
|
case .Windows:
|
||||||
dir = get_env("AppData", allocator)
|
dir = get_env("AppData", temp_allocator())
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
dir = clone_string(dir, allocator) or_return
|
dir = clone_string(dir, allocator) or_return
|
||||||
}
|
}
|
||||||
case .Darwin:
|
case .Darwin:
|
||||||
dir = get_env("HOME", allocator)
|
dir = get_env("HOME", temp_allocator())
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
dir = concatenate({dir, "/.config"}, allocator) or_return
|
dir = concatenate({dir, "/.config"}, allocator) or_return
|
||||||
}
|
}
|
||||||
case: // All other UNIX systems
|
case: // All other UNIX systems
|
||||||
dir = get_env("XDG_CACHE_HOME", allocator)
|
dir = get_env("XDG_CACHE_HOME", allocator)
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
dir = get_env("HOME", allocator)
|
dir = get_env("HOME", temp_allocator())
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user