commit 88281a76b99c430f41f651baaa6b53eef27fc07e
parent 7315d856a1485f20691652cc9b2e4165d8095cc4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 21 Nov 2021 18:20:14 +0100
libc: Don't trash errno in malloc()
The errno value must be set as near of the error as it happens.
Modyfing the value of errno in a place where the error is not
generated drives to incorrect diagnosis messages.
Diffstat:
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/libc/stdlib/malloc.c b/src/libc/stdlib/malloc.c
@@ -1,4 +1,3 @@
-#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -153,10 +152,8 @@ malloc(size_t nbytes)
}
if (cur == freep) {
- if ((cur = morecore(nunits)) == NULL) {
- errno = ENOMEM;
+ if ((cur = morecore(nunits)) == NULL)
return NULL;
- }
}
}
}