aboutsummaryrefslogtreecommitdiff
path: root/src/wav
diff options
context:
space:
mode:
authorSan Jacobs2026-05-11 23:10:39 +0200
committerSan Jacobs2026-05-11 23:10:39 +0200
commit8fdea54e718157389ef5c2df6864d9cd3e895897 (patch)
tree6940b3a4b4b4efb97cb4c4a8773c797045f036b7 /src/wav
parentb4da4c036cb6e32754dd4a26ef7de9633bf4ef0d (diff)
downloadbetter-report-8fdea54e718157389ef5c2df6864d9cd3e895897.tar.gz
better-report-8fdea54e718157389ef5c2df6864d9cd3e895897.tar.bz2
better-report-8fdea54e718157389ef5c2df6864d9cd3e895897.zip
New odin version and fixed various file handle and memory leaks
Diffstat (limited to 'src/wav')
-rw-r--r--src/wav/wav.odin16
-rw-r--r--src/wav/xml/xml_reader.odin4
2 files changed, 11 insertions, 9 deletions
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) {
diff --git a/src/wav/xml/xml_reader.odin b/src/wav/xml/xml_reader.odin
index c19cbf6..b277a5e 100644
--- a/src/wav/xml/xml_reader.odin
+++ b/src/wav/xml/xml_reader.odin
@@ -377,8 +377,8 @@ load_from_file :: proc(filename: string, options := DEFAULT_OPTIONS, error_handl
context.allocator = allocator
options := options
- data, data_ok := os.read_entire_file(filename)
- if !data_ok { return {}, .File_Error }
+ data, data_err := os.read_entire_file(filename, context.allocator)
+ if data_err != nil { return {}, .File_Error }
options.flags += { .Input_May_Be_Modified }