Skip to content

Free the scratch buffer in WavWriter::Write - #11

Open
lylepmills wants to merge 1 commit into
pichenettes:masterfrom
lylepmills:fix-wav-writer-leak
Open

Free the scratch buffer in WavWriter::Write#11
lylepmills wants to merge 1 commit into
pichenettes:masterfrom
lylepmills:fix-wav-writer-leak

Conversation

@lylepmills

Copy link
Copy Markdown

Both Write() overloads calloc a temporary int16_t buffer, convert into it, fwrite it, and 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 16,000 allocations / 768,000 bytes. That's enough to make an AddressSanitizer build of a test harness fail on exit, which is how I ran into it.

The buffer isn't referenced after the fwrite, and the destructor doesn't reclaim it, so freeing it immediately is sufficient. <cstdlib> is already included for calloc, so no new include is needed.

Verified with a plaits test harness built -fsanitize=address: LeakSanitizer reports the calloc site before the change and is clean after, and the rendered WAV is byte-identical either way.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant