From 95a540e176b3ebd57d6033fd23cf9fec8a5ddbe8 Mon Sep 17 00:00:00 2001 From: Dominic Chen Date: Thu, 25 Mar 2021 18:20:14 -0400 Subject: mallocng/aligned_alloc: check for malloc failure With mallocng, calling posix_memalign() or aligned_alloc() will SIGSEGV if the internal malloc() call returns NULL. This does not occur with oldmalloc, which explicitly checks for allocation failure. --- src/malloc/mallocng/aligned_alloc.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/malloc/mallocng/aligned_alloc.c b/src/malloc/mallocng/aligned_alloc.c index 34116896..e0862a83 100644 --- a/src/malloc/mallocng/aligned_alloc.c +++ b/src/malloc/mallocng/aligned_alloc.c @@ -22,6 +22,9 @@ void *aligned_alloc(size_t align, size_t len) if (align <= UNIT) align = UNIT; unsigned char *p = malloc(len + align - UNIT); + if (!p) + return 0; + struct meta *g = get_meta(p); int idx = get_slot_index(p); size_t stride = get_stride(g); -- cgit 1.4.1