Repository navigation
cache_meta: keep a build buffer when growing it fails - #59
Merged
Merged
Conversation
meta_build() collects a directory in two buffers and makes them larger as it goes. Both callers of meta_grow() stored its result straight into the pointer they were growing. When there was no memory for the larger copy, that pointer became NULL, the buffer it had pointed to was never freed, and the build went on to fail. Take the result in a variable of its own and replace the pointer only if there is one. The old buffer then stays with the build, which frees it on the way out as it does after every other failure. The string pool starts at 16 bytes per estimated entry and names are often longer, so it does grow on ordinary discs. For the leak the handler had to run out of memory at that moment. Add a unit test that lets one more allocation succeed each round and counts the blocks that are not given back.
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.
cache_meta: keep a build buffer when growing it fails
The first time a directory is listed, the handler collects its entries in two buffers and makes them larger as it goes. If there was no memory for the larger copy, the old buffer was lost: both callers of
meta_grow()stored its result straight into the pointer they were growing, so the pointer became NULL and the cleanup had nothing to free.Found while counting the handler's allocations with a patch on exec's allocator. Nothing reported it.
Testing
test_cache_meta_nomem: it builds the cache with an allocator that fails from the Nth allocation on and counts the blocks that are not given back, letting one more allocation succeed each round until the build goes through. On main it fails with one block left; with the fix it passes.make check,golden-check,malformed-checkandfuzz-checkpass.tests/aros/check_abi.shpasses.Size: +4 bytes on the 68000 and 68020 handlers, ROM unchanged.