From 31943d2ecd8687af42f6f35f75971721ba213075 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 16 Mar 2024 19:29:49 +0100 Subject: [PATCH] wutmalloc: make sure to set errno properly on error --- libraries/wutmalloc/wut_malloc.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libraries/wutmalloc/wut_malloc.c b/libraries/wutmalloc/wut_malloc.c index 4ee487420..24573c6bd 100644 --- a/libraries/wutmalloc/wut_malloc.c +++ b/libraries/wutmalloc/wut_malloc.c @@ -66,7 +66,11 @@ _calloc_r(struct _reent *r, size_t num, size_t size) void * _memalign_r(struct _reent *r, size_t align, size_t size) { - return MEMAllocFromDefaultHeapEx((size + align - 1) & ~(align - 1), align); + void *ptr = MEMAllocFromDefaultHeapEx((size + align - 1) & ~(align - 1), align); + if (!ptr) { + r->_errno = ENOMEM; + } + return ptr; } struct mallinfo _mallinfo_r(struct _reent *r) @@ -95,13 +99,21 @@ _malloc_usable_size_r(struct _reent *r, void *ptr) void * _valloc_r(struct _reent *r, size_t size) { - return MEMAllocFromDefaultHeapEx(size, OS_PAGE_SIZE); + void *ptr = MEMAllocFromDefaultHeapEx(size, OS_PAGE_SIZE); + if (!ptr) { + r->_errno = ENOMEM; + } + return ptr; } void * _pvalloc_r(struct _reent *r, size_t size) { - return MEMAllocFromDefaultHeapEx((size + (OS_PAGE_SIZE - 1)) & ~(OS_PAGE_SIZE - 1), OS_PAGE_SIZE); + void *ptr = MEMAllocFromDefaultHeapEx((size + (OS_PAGE_SIZE - 1)) & ~(OS_PAGE_SIZE - 1), OS_PAGE_SIZE); + if (!ptr) { + r->_errno = ENOMEM; + } + return ptr; } int