From 8fdea54e718157389ef5c2df6864d9cd3e895897 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Mon, 11 May 2026 23:10:39 +0200 Subject: New odin version and fixed various file handle and memory leaks --- src/wav/wav.odin | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/wav/wav.odin') diff --git a/src/wav/wav.odin b/src/wav/wav.odin index 0d148c7..dc5923f 100644 --- a/src/wav/wav.odin +++ b/src/wav/wav.odin @@ -29,7 +29,7 @@ Wav :: struct { audio : [][]f32, // Internals - handle : os.Handle, + handle : ^os.File, load_head : int, // Metadata @@ -120,9 +120,7 @@ read :: proc(path : string, allocator := context.allocator) -> (Wav, bool) #opti load_err : os.Error file.handle, load_err = os.open(path) - defer os.close(file.handle) - defer file.handle = 0 - if load_err != os.General_Error.None { + if load_err != nil { fmt.eprintfln("ERROR %v: Unable to load file \"%v\"", load_err, path) return {}, false } @@ -471,7 +469,8 @@ read :: proc(path : string, allocator := context.allocator) -> (Wav, bool) #opti naming_channel := 0 description := string(temp_bext[:256]) - for line in strings.split_lines(description) { + lines := strings.split_lines(description) + for line in lines { if len(line)<1 do continue if file.channel_names[naming_channel] == "" && (strings.starts_with(line, "sTRK") || strings.starts_with(line, "zTRK")) { @@ -512,6 +511,7 @@ read :: proc(path : string, allocator := context.allocator) -> (Wav, bool) #opti } } } + delete(lines) head := 0 when VERBOSE do fmt.printf("Description: \n%v\n", string(temp_bext[head:256])) head += 256 @@ -548,6 +548,9 @@ read :: proc(path : string, allocator := context.allocator) -> (Wav, bool) #opti // just here to make some printing prettier temp_bext = nil + os.close(file.handle) + file.handle = nil + return file, true } @@ -640,8 +643,7 @@ tprint_timecode :: proc(file : Wav) -> string { } print_timecode :: proc(file : Wav, allocator := context.allocator) -> string { tc := get_timecode(file) - using tc - return fmt.aprintf("%02d:%02d:%02d:%02d",hour,minute,second,frame, + return fmt.aprintf("%02d:%02d:%02d:%02d", tc.hour, tc.minute, tc.second, tc.frame, allocator=allocator) } get_timecode :: proc(file : Wav) -> (output:Timecode) { -- cgit v1.2.1