Repository navigation
realloc(NULL, 0) is malloc(0), fix realloc of small big-aligned chunks - #247
Merged
Merged
Conversation
realloc(NULL, 0) returned NULL, which gnulib's xrealloc treats as out of memory, so grep and sed died with "memory exhausted" under LD_PRELOAD. realloc(NULL, size) now calls iso_alloc(size) for every size, so it returns exactly what malloc(0) returns: the shared no-access page by default, or a unique chunk when built with NO_ZERO_ALLOCATIONS=0. A request with an alignment above the page size is served from a big zone even when the size is small. realloc of such a chunk released it through _iso_free_size, which only searched the small zones and aborted with "Could not find zone". It now falls back to the big zone list. Adds tests/preload/libc_semantics.c covering zero sized malloc, calloc, realloc and reallocarray, realloc(NULL, 0) matching malloc(0), and posix_memalign / aligned_alloc for every power of two up to 4 MB followed by realloc. On Linux the preload runner also runs grep, sed, sort and ls under the library. Reported in daanx/mimalloc-bench#295 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NBUcR6B9g4yn7x7fstjXfk
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.
realloc(NULL, 0) returned NULL, which gnulib's xrealloc treats as
out of memory, so grep and sed died with "memory exhausted" under
LD_PRELOAD. realloc(NULL, size) now calls iso_alloc(size) for every
size, so it returns exactly what malloc(0) returns: the shared
no-access page by default, or a unique chunk when built with
NO_ZERO_ALLOCATIONS=0.
A request with an alignment above the page size is served from a
big zone even when the size is small. realloc of such a chunk
released it through _iso_free_size, which only searched the small
zones and aborted with "Could not find zone". It now falls back to
the big zone list.
Adds tests/preload/libc_semantics.c covering zero sized malloc,
calloc, realloc and reallocarray, realloc(NULL, 0) matching
malloc(0), and posix_memalign / aligned_alloc for every power of
two up to 4 MB followed by realloc. On Linux the preload runner
also runs grep, sed, sort and ls under the library.
Reported in daanx/mimalloc-bench#295
Co-Authored-By: Claude Fable 5.2 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01NBUcR6B9g4yn7x7fstjXfk