From ac9168f37628a89e616ff1a198e85b065fd3063d Mon Sep 17 00:00:00 2001 From: Lyle Mills Date: Mon, 27 Jul 2026 10:29:51 -0700 Subject: [PATCH] Free the scratch buffer in WavWriter::Write Both Write() overloads calloc a temporary int16 buffer, convert into it, fwrite it, and then return without freeing it. The allocation happens once per call, so a test that renders in blocks leaks steadily for the length of the render: a 4-second stereo render at a 24-sample block size leaks 16000 allocations / 768000 bytes, which is enough to make an AddressSanitizer build of a test harness fail on exit. The buffer is not referenced after the fwrite, so freeing it immediately is sufficient. Adds free(short_buffer) to both overloads. Reproduced with a plaits test harness built -fsanitize=address; LeakSanitizer reports the calloc site before the change and is clean after it. --- test/wav_writer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/wav_writer.h b/test/wav_writer.h index 4b08c9ad..8722736f 100755 --- a/test/wav_writer.h +++ b/test/wav_writer.h @@ -100,6 +100,7 @@ class WavWriter { short_buffer[i] = static_cast(x); } fwrite(short_buffer, sizeof(int16_t), size, fp_); + free(short_buffer); remaining_frames_ -= size / num_channels_; } @@ -120,6 +121,7 @@ class WavWriter { } } fwrite(short_buffer, sizeof(int16_t), size * 2, fp_); + free(short_buffer); remaining_frames_ -= size; }