Skip to content

Commit 8ee51bc

Browse files
committed
Fixed an Odin memory leak
See odin-lang/Odin#4680
1 parent a4a0e86 commit 8ee51bc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/main.odin

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package main
22

3+
import "base:runtime" // args__
4+
35
import "core:fmt"
46
import "core:math"
57
import "core:mem"
6-
import "core:os"
78
import "core:strings"
89

910
import lex "lexer"
@@ -76,13 +77,24 @@ math_max :: proc(ctx: ^run.Exec_Context, args: ^run.Fun_Args_Iterator) -> (res:
7677
return
7778
}
7879

80+
make_os_args :: proc() -> (argv: []string) {
81+
// See https://github.com/odin-lang/Odin/pull/4680
82+
// And https://github.com/odin-lang/Odin/pull/4680#issuecomment-2585475395
83+
argv = make([]string, len(runtime.args__))
84+
for _, i in argv do argv[i] = string(runtime.args__[i])
85+
return
86+
}
87+
7988
main :: proc() {
80-
if len(os.args) <= 1 {
89+
os_args := make_os_args()
90+
defer delete(os_args)
91+
92+
if len(os_args) <= 1 {
8193
fmt.println("ERROR: No expression provided.")
8294
return
8395
}
8496

85-
expr_source := strings.join(os.args[1:], " ")
97+
expr_source := strings.join(os_args[1:], " ")
8698
defer delete(expr_source)
8799

88100
parser: parse.Parser

0 commit comments

Comments
 (0)