fix: get rid of a use-after-free bug that happens when using the default heap allocator

This commit is contained in:
2024-06-20 05:00:35 +02:00
parent 3c482fc63a
commit 5e23cc8f58
5 changed files with 74 additions and 30 deletions
+6 -7
View File
@@ -16,6 +16,7 @@ main :: proc() {
fmt.eprintln("Please provide a path to a flac file.")
os.exit(1)
}
defer delete(os.args)
handle: ^alsa.pcm_t
@@ -61,14 +62,12 @@ main :: proc() {
converted_samples[i] = i16(new_sample)
}
for {
frames := alsa.pcm_writei(handle, raw_data(converted_samples), u64(len(flac_data.samples)) / u64(flac_data.metadata.channels))
if frames < 0 {
fmt.eprintln("Error writing to PCM device:", alsa.strerror(auto_cast frames))
break
}
fmt.printfln("Played %d frames", frames)
frames := alsa.pcm_writei(handle, raw_data(converted_samples), u64(len(flac_data.samples)) / u64(flac_data.metadata.channels))
if frames < 0 {
fmt.eprintln("Error writing to PCM device:", alsa.strerror(auto_cast frames))
return
}
fmt.printfln("Played %d frames", frames)
alsa_err = alsa.pcm_drain(handle)
if alsa_err < 0 {