diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2022-03-29 16:13:17 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2022-03-29 16:13:17 +0200 |
| commit | df32b5b46c03b6e2955af026074831eebd0e18d6 (patch) | |
| tree | c7eafc02160b20ca0b38aa1fa7cc89dd466e3014 /core/sys/windows/util.odin | |
| parent | 085fa199eaf28b9544293a4ef1d2f8637e242af9 (diff) | |
[windows] Fix leak in `glob`.
Diffstat (limited to 'core/sys/windows/util.odin')
| -rw-r--r-- | core/sys/windows/util.odin | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin index efb37dbc0..5797216c3 100644 --- a/core/sys/windows/util.odin +++ b/core/sys/windows/util.odin @@ -45,7 +45,9 @@ utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> wstri return nil } -wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator) -> string { +wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator) -> (res: string) { + context.allocator = allocator + if N <= 0 { return "" } @@ -60,7 +62,7 @@ wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator) // also null terminated. // If N != -1 it assumes the wide string is not null terminated and the resulting string // will not be null terminated, we therefore have to force it to be null terminated manually. - text := make([]byte, n+1 if N != -1 else n, allocator) + text := make([]byte, n+1 if N != -1 else n) n1 := WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), raw_data(text), n, nil, nil) if n1 == 0 { @@ -74,7 +76,6 @@ wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator) break } } - return string(text[:n]) } |