From a947d317a2769d90bdb19aa11942b7a0680051d5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 5 Oct 2013 11:59:21 -0400 Subject: [PATCH] fix failure of malloc to set errno on heap (brk) exhaustion I wrongly assumed the brk syscall would set errno, but on failure it returns the old value of the brk rather than an error code. --- src/malloc/malloc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index fb65ab5b..d6ad9041 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -177,6 +177,7 @@ static struct chunk *expand_heap(size_t n) return w; fail: unlock(mal.brk_lock); + errno = ENOMEM; return 0; } -- 2.25.1