From dd25eb85386d00036f132ad8475c7631a6712209 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 9 Sep 2026 21:12:29 +0530 Subject: [PATCH] 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. --- kitty/arena.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kitty/arena.h b/kitty/arena.h index 247f90583..b14769d77 100644 --- a/kitty/arena.h +++ b/kitty/arena.h @@ -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) {