[klibc] malloc: Set errno on failure
authorBen Hutchings <ben@decadent.org.uk>
Wed, 28 Apr 2021 01:57:39 +0000 (03:57 +0200)
committerThorsten Glaser <tg@mirbsd.de>
Wed, 26 May 2021 22:12:10 +0000 (23:12 +0100)
Origin: https://git.kernel.org/pub/scm/libs/klibc/klibc.git/commit/?id=7f6626d12daa2f1efd9953d1f4ba2065348dc5cd

malloc() is specified to set errno = ENOMEM on failure, so do that.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Name 0035-klibc-malloc-Set-errno-on-failure.patch

usr/klibc/malloc.c

index 413b7337be95c02328e34a50cf484cec3c0c5cc8..bb57c9f6ffd34ab8f8408887cde939f5bac5e3c2 100644 (file)
@@ -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
@@ -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 */
        }