Free the scratch buffer in WavWriter::Write - #11
Open
lylepmills wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both
Write()overloadscalloca temporaryint16_tbuffer, convert into it,fwriteit, 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 forcalloc, so no new include is needed.Verified with a plaits test harness built
-fsanitize=address: LeakSanitizer reports thecallocsite before the change and is clean after, and the rendered WAV is byte-identical either way.