arena: do not memset a NULL pointer when posix_memalign fails

The memset was run unconditionally after posix_memalign, so an
allocation failure crashed in memset instead of returning NULL to the
caller, defeating the OOM handling in every arena user.
This commit is contained in:
Kovid Goyal 2026-09-09 21:12:29 +05:30
parent 5a1341a4d9
commit dd25eb8538
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -52,7 +52,7 @@ MA_CAT(MA_NAME, _get)(MA_TYPE_NAME *self, size_t sz) {
void *chunk = NULL;
if (MA_BLOCK_SIZE >= sizeof(void *) && MA_BLOCK_SIZE % sizeof(void *) == 0) {
if (posix_memalign(&chunk, MA_BLOCK_SIZE, block_sz) != 0) chunk = NULL;
memset(chunk, 0, block_sz);
else memset(chunk, 0, block_sz);
} else chunk = calloc(1, block_sz);
if (!chunk) { return NULL; }
if (count > self->capacity) {