diff --git a/vlib/os/os.v b/vlib/os/os.v index bf17571766..dcc42cb9c1 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -100,6 +100,8 @@ fn init_os_args(argc int, argv *byteptr) []string { for i := 0; i < args_count; i++ { args << string_from_wide(&u16(args_list[i])) } + + C.LocalFree(args_list) } $else { for i := 0; i < argc; i++ { args << string(argv[i]) @@ -520,7 +522,7 @@ pub fn get_line() string { pub fn get_raw_line() string { $if windows { max := 512 // MAX_PATH * sizeof(wchar_t) - buf := &u16(malloc(max)) + buf := &u16(malloc(max*2)) h_input := C.GetStdHandle(STD_INPUT_HANDLE) if h_input == INVALID_HANDLE_VALUE { panic('get_raw_line() error getting input handle.') @@ -658,8 +660,9 @@ pub fn executable() string { return string(result, count) } $if windows { - mut result := &u16(malloc(512)) // MAX_PATH * sizeof(wchar_t) - len := int(C.GetModuleFileName( 0, result, MAX_PATH )) + max := 512 + mut result := &u16(malloc(max*2)) // MAX_PATH * sizeof(wchar_t) + len := int(C.GetModuleFileName( 0, result, max )) return string_from_wide2(result, len) } $if mac { @@ -731,9 +734,9 @@ pub fn chdir(path string) { pub fn getwd() string { $if windows { - max := 1024 // MAX_PATH * sizeof(wchar_t) - buf := &u16(malloc(max)) - if C._wgetcwd(buf, max/2) == 0 { + max := 512 // MAX_PATH * sizeof(wchar_t) + buf := &u16(malloc(max*2)) + if C._wgetcwd(buf, max) == 0 { return '' } return string_from_wide(buf)