Skip to content

Commit

Permalink
wutmalloc: make sure to set errno properly on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell authored and fincs committed Apr 5, 2024
1 parent 3242650 commit 31943d2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions libraries/wutmalloc/wut_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 31943d2

Please sign in to comment.