aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Chen <d.c.ddcc@gmail.com>2021-03-25 18:20:14 -0400
committerRich Felker <dalias@aerifal.cx>2021-04-16 10:17:25 -0400
commit95a540e176b3ebd57d6033fd23cf9fec8a5ddbe8 (patch)
tree806cf2f44b88afa4eda056be40d134aa8149160a
parent2c00f95c1ac7dd50f53d9e361847ebd2513c8da0 (diff)
downloadmusl-95a540e176b3ebd57d6033fd23cf9fec8a5ddbe8.tar.gz
musl-95a540e176b3ebd57d6033fd23cf9fec8a5ddbe8.tar.xz
musl-95a540e176b3ebd57d6033fd23cf9fec8a5ddbe8.zip
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.
-rw-r--r--src/malloc/mallocng/aligned_alloc.c3
1 files changed, 3 insertions, 0 deletions
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);