Skip to content

Commit

Permalink
[klibc] malloc: Set errno on failure
Browse files Browse the repository at this point in the history
malloc() is specified to set errno = ENOMEM on failure, so do that.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
  • Loading branch information
bwhacks committed Apr 28, 2021
1 parent 8e88e0a commit 7f6626d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions usr/klibc/malloc.c
Expand Up @@ -8,6 +8,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include <assert.h>
#include <errno.h>
#include "malloc.h"

/* Both the arena list and the free memory list are double linked
Expand Down Expand Up @@ -169,6 +170,7 @@ void *malloc(size_t size)
#endif

if (fp == (struct free_arena_header *)MAP_FAILED) {
errno = ENOMEM;
return NULL; /* Failed to get a block */
}

Expand Down

0 comments on commit 7f6626d

Please sign in to comment.