Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we don't leak os.args. Fixes #1633. #4680

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion core/os/os_darwin.odin
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,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 {
Expand All @@ -1205,6 +1205,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 {
Expand Down
7 changes: 6 additions & 1 deletion core/os/os_freebsd.odin
Original file line number Diff line number Diff line change
Expand Up @@ -936,11 +936,16 @@ _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__ {
res[i] = string(arg)
}
return res
}

@(private, fini)
_delete_command_line_arguments :: proc() {
delete(args)
}
7 changes: 6 additions & 1 deletion core/os/os_haiku.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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__ {
Expand All @@ -325,6 +325,11 @@ _alloc_command_line_arguments :: proc() -> []string {
return res
}

@(private, fini)
_delete_command_line_arguments :: proc() {
delete(args)
}

@(private, require_results)
_stat :: proc(path: string) -> (OS_Stat, Error) {
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
Expand Down
7 changes: 6 additions & 1 deletion core/os/os_linux.odin
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,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__ {
Expand All @@ -1078,6 +1078,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)
Expand Down
7 changes: 6 additions & 1 deletion core/os/os_netbsd.odin
Original file line number Diff line number Diff line change
Expand Up @@ -986,11 +986,16 @@ _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__ {
res[i] = string(arg)
}
return res
}

@(private, fini)
_delete_command_line_arguments :: proc() {
delete(args)
}
7 changes: 6 additions & 1 deletion core/os/os_openbsd.odin
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,16 @@ _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__ {
res[i] = string(arg)
}
return res
}

@(private, fini)
_delete_command_line_arguments :: proc() {
delete(args)
}
7 changes: 6 additions & 1 deletion core/os/os_wasi.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion core/os/os_windows.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
Loading