fix failure of malloc to set errno on heap (brk) exhaustion
authorRich Felker <dalias@aerifal.cx>
Sat, 5 Oct 2013 15:59:21 +0000 (11:59 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 5 Oct 2013 15:59:21 +0000 (11:59 -0400)
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

index fb65ab5bb180416166c94c8eca84d6567507dd4f..d6ad90414fc799f861ed58500d56b62b611ffa6e 100644 (file)
@@ -177,6 +177,7 @@ static struct chunk *expand_heap(size_t n)
        return w;
 fail:
        unlock(mal.brk_lock);
+       errno = ENOMEM;
        return 0;
 }