diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-06-27 01:27:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-27 01:27:28 +0200 |
| commit | 0f79bafed27332ef037585aa7d8095391620563d (patch) | |
| tree | bc5e666006bf43931bc793ac921061b5630db4d4 | |
| parent | f72b2b153057e1d629c85af2ea7c54f7928198d5 (diff) | |
| parent | 2e83e221419b480160dbf11dd09edf8b5fa97f32 (diff) | |
Merge pull request #4680 from haesbaert/args-leak
Make sure we don't leak os.args. Fixes #1633.
| -rw-r--r-- | core/os/os_darwin.odin | 7 | ||||
| -rw-r--r-- | core/os/os_freebsd.odin | 7 | ||||
| -rw-r--r-- | core/os/os_haiku.odin | 7 | ||||
| -rw-r--r-- | core/os/os_linux.odin | 7 | ||||
| -rw-r--r-- | core/os/os_netbsd.odin | 7 | ||||
| -rw-r--r-- | core/os/os_openbsd.odin | 7 | ||||
| -rw-r--r-- | core/os/os_wasi.odin | 7 | ||||
| -rw-r--r-- | core/os/os_windows.odin | 10 |
8 files changed, 51 insertions, 8 deletions
diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index b247b1000..18f80623d 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -1225,7 +1225,7 @@ _processor_core_count :: proc() -> int { return 1 } -@(require_results) +@(private, require_results) _alloc_command_line_arguments :: proc() -> []string { res := make([]string, len(runtime.args__)) for _, i in res { @@ -1234,6 +1234,11 @@ _alloc_command_line_arguments :: proc() -> []string { return res } +@(private, fini) +_delete_command_line_arguments :: proc() { + delete(args) +} + socket :: proc(domain: int, type: int, protocol: int) -> (Socket, Error) { result := _unix_socket(c.int(domain), c.int(type), c.int(protocol)) if result < 0 { diff --git a/core/os/os_freebsd.odin b/core/os/os_freebsd.odin index a4c3c819e..f57c464ac 100644 --- a/core/os/os_freebsd.odin +++ b/core/os/os_freebsd.odin @@ -964,7 +964,7 @@ _processor_core_count :: proc() -> int { } -@(require_results) +@(private, require_results) _alloc_command_line_arguments :: proc() -> []string { res := make([]string, len(runtime.args__)) for arg, i in runtime.args__ { @@ -972,3 +972,8 @@ _alloc_command_line_arguments :: proc() -> []string { } return res } + +@(private, fini) +_delete_command_line_arguments :: proc() { + delete(args) +} diff --git a/core/os/os_haiku.odin b/core/os/os_haiku.odin index 82ead06ab..b56d516a4 100644 --- a/core/os/os_haiku.odin +++ b/core/os/os_haiku.odin @@ -316,7 +316,7 @@ file_size :: proc(fd: Handle) -> (i64, Error) { // "Argv" arguments converted to Odin strings args := _alloc_command_line_arguments() -@(require_results) +@(private, require_results) _alloc_command_line_arguments :: proc() -> []string { res := make([]string, len(runtime.args__)) for arg, i in runtime.args__ { @@ -325,6 +325,11 @@ _alloc_command_line_arguments :: proc() -> []string { return res } +@(private, fini) +_delete_command_line_arguments :: proc() { + delete(args) +} + @(private, require_results, no_sanitize_memory) _stat :: proc(path: string) -> (OS_Stat, Error) { runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD() diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index c14f573bf..683c893f9 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -1097,7 +1097,7 @@ _processor_core_count :: proc() -> int { return int(_unix_get_nprocs()) } -@(require_results) +@(private, require_results) _alloc_command_line_arguments :: proc() -> []string { res := make([]string, len(runtime.args__)) for arg, i in runtime.args__ { @@ -1106,6 +1106,11 @@ _alloc_command_line_arguments :: proc() -> []string { return res } +@(private, fini) +_delete_command_line_arguments :: proc() { + delete(args) +} + @(require_results) socket :: proc(domain: int, type: int, protocol: int) -> (Socket, Error) { result := unix.sys_socket(domain, type, protocol) diff --git a/core/os/os_netbsd.odin b/core/os/os_netbsd.odin index d1e030e8e..efdd852fe 100644 --- a/core/os/os_netbsd.odin +++ b/core/os/os_netbsd.odin @@ -1014,7 +1014,7 @@ _processor_core_count :: proc() -> int { return 1 } -@(require_results) +@(private, require_results) _alloc_command_line_arguments :: proc() -> []string { res := make([]string, len(runtime.args__)) for arg, i in runtime.args__ { @@ -1022,3 +1022,8 @@ _alloc_command_line_arguments :: proc() -> []string { } return res } + +@(private, fini) +_delete_command_line_arguments :: proc() { + delete(args) +} diff --git a/core/os/os_openbsd.odin b/core/os/os_openbsd.odin index 993bff252..c68f7943c 100644 --- a/core/os/os_openbsd.odin +++ b/core/os/os_openbsd.odin @@ -914,7 +914,7 @@ _processor_core_count :: proc() -> int { return int(_sysconf(_SC_NPROCESSORS_ONLN)) } -@(require_results) +@(private, require_results) _alloc_command_line_arguments :: proc() -> []string { res := make([]string, len(runtime.args__)) for arg, i in runtime.args__ { @@ -922,3 +922,8 @@ _alloc_command_line_arguments :: proc() -> []string { } return res } + +@(private, fini) +_delete_command_line_arguments :: proc() { + delete(args) +} diff --git a/core/os/os_wasi.odin b/core/os/os_wasi.odin index 4039d247b..f135e4d42 100644 --- a/core/os/os_wasi.odin +++ b/core/os/os_wasi.odin @@ -27,7 +27,7 @@ stderr: Handle = 2 args := _alloc_command_line_arguments() -@(require_results) +@(private, require_results) _alloc_command_line_arguments :: proc() -> (args: []string) { args = make([]string, len(runtime.args__)) for &arg, i in args { @@ -36,6 +36,11 @@ _alloc_command_line_arguments :: proc() -> (args: []string) { return } +@(private, fini) +_delete_command_line_arguments :: proc() { + delete(args) +} + // WASI works with "preopened" directories, the environment retrieves directories // (for example with `wasmtime --dir=. module.wasm`) and those given directories // are the only ones accessible by the application. diff --git a/core/os/os_windows.odin b/core/os/os_windows.odin index 0c532bf14..3c1725cc5 100644 --- a/core/os/os_windows.odin +++ b/core/os/os_windows.odin @@ -193,7 +193,7 @@ current_thread_id :: proc "contextless" () -> int { -@(require_results) +@(private, require_results) _alloc_command_line_arguments :: proc() -> []string { arg_count: i32 arg_list_ptr := win32.CommandLineToArgvW(win32.GetCommandLineW(), &arg_count) @@ -215,6 +215,14 @@ _alloc_command_line_arguments :: proc() -> []string { return arg_list } +@(private, fini) +_delete_command_line_arguments :: proc() { + for s in args { + delete(s) + } + delete(args) +} + /* Windows 11 (preview) has the same major and minor version numbers as Windows 10: 10 and 0 respectively. |