mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
fixed memory leak from calling get_env
This commit is contained in:
+10
-10
@@ -6,19 +6,19 @@ import "core:runtime"
|
|||||||
user_cache_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
user_cache_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||||
#partial switch ODIN_OS {
|
#partial switch ODIN_OS {
|
||||||
case .Windows:
|
case .Windows:
|
||||||
dir = get_env("LocalAppData")
|
dir = get_env("LocalAppData", allocator)
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
dir = strings.clone_safe(dir, allocator) or_return
|
dir = strings.clone_safe(dir, allocator) or_return
|
||||||
}
|
}
|
||||||
case .Darwin:
|
case .Darwin:
|
||||||
dir = get_env("HOME")
|
dir = get_env("HOME", allocator)
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
dir = strings.concatenate_safe({dir, "/Library/Caches"}, allocator) or_return
|
dir = strings.concatenate_safe({dir, "/Library/Caches"}, allocator) or_return
|
||||||
}
|
}
|
||||||
case: // All other UNIX systems
|
case: // All other UNIX systems
|
||||||
dir = get_env("XDG_CACHE_HOME")
|
dir = get_env("XDG_CACHE_HOME", allocator)
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
dir = get_env("HOME")
|
dir = get_env("HOME", allocator)
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -34,19 +34,19 @@ user_cache_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error
|
|||||||
user_config_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
user_config_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||||
#partial switch ODIN_OS {
|
#partial switch ODIN_OS {
|
||||||
case .Windows:
|
case .Windows:
|
||||||
dir = get_env("AppData")
|
dir = get_env("AppData", allocator)
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
dir = strings.clone_safe(dir, allocator) or_return
|
dir = strings.clone_safe(dir, allocator) or_return
|
||||||
}
|
}
|
||||||
case .Darwin:
|
case .Darwin:
|
||||||
dir = get_env("HOME")
|
dir = get_env("HOME", allocator)
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
dir = strings.concatenate_safe({dir, "/Library/Application Support"}, allocator) or_return
|
dir = strings.concatenate_safe({dir, "/Library/Application Support"}, allocator) or_return
|
||||||
}
|
}
|
||||||
case: // All other UNIX systems
|
case: // All other UNIX systems
|
||||||
dir = get_env("XDG_CACHE_HOME")
|
dir = get_env("XDG_CACHE_HOME", allocator)
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
dir = get_env("HOME")
|
dir = get_env("HOME", allocator)
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -59,13 +59,13 @@ user_config_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Erro
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user_home_dir :: proc() -> (dir: string, err: Error) {
|
user_home_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||||
env := "HOME"
|
env := "HOME"
|
||||||
#partial switch ODIN_OS {
|
#partial switch ODIN_OS {
|
||||||
case .Windows:
|
case .Windows:
|
||||||
env = "USERPROFILE"
|
env = "USERPROFILE"
|
||||||
}
|
}
|
||||||
if v := get_env(env); v != "" {
|
if v := get_env(env, allocator); v != "" {
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
return "", .Invalid_Path
|
return "", .Invalid_Path
|
||||||
|
|||||||
Reference in New Issue
Block a user