From 63deae5e4f186a453fb6fbab0d8acf314aab4df0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 4 Sep 2012 15:42:23 -0700 Subject: [PATCH] Add missing MALLOC_FAILURE_ACTION calls to dlmalloc. Without these, sometimes malloc(3) returns NULL without setting errno. Change-Id: I4708c3f675bf2c878ddcaf012fde7848b255826b --- libc/upstream-dlmalloc/malloc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libc/upstream-dlmalloc/malloc.c b/libc/upstream-dlmalloc/malloc.c index 5e675b459..0a1f6b29f 100644 --- a/libc/upstream-dlmalloc/malloc.c +++ b/libc/upstream-dlmalloc/malloc.c @@ -4049,12 +4049,20 @@ static void* sys_alloc(mstate m, size_t nb) { } asize = granularity_align(nb + SYS_ALLOC_PADDING); - if (asize <= nb) + if (asize <= nb) { + /* BEGIN android-added: set errno */ + MALLOC_FAILURE_ACTION; + /* END android-added */ return 0; /* wraparound */ + } if (m->footprint_limit != 0) { size_t fp = m->footprint + asize; - if (fp <= m->footprint || fp > m->footprint_limit) + if (fp <= m->footprint || fp > m->footprint_limit) { + /* BEGIN android-added: set errno */ + MALLOC_FAILURE_ACTION; + /* END android-added */ return 0; + } } /*