* [musl] [PATCH] mallocng/aligned_alloc: check for malloc failure
@ 2021-03-25 22:26 Dominic Chen
2021-04-16 14:17 ` Rich Felker
0 siblings, 1 reply; 2+ messages in thread
From: Dominic Chen @ 2021-03-25 22:26 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 221 bytes --]
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.
Thanks,
Dominic
[-- Attachment #2: 0001-mallocng-aligned_alloc-check-for-malloc-failure.patch --]
[-- Type: text/plain, Size: 785 bytes --]
From 83a79b341f75ad243fba8603d889bfdebae3f35b Mon Sep 17 00:00:00 2001
From: Dominic Chen <d.c.ddcc@gmail.com>
Date: Thu, 25 Mar 2021 18:20:14 -0400
Subject: [PATCH] mallocng/aligned_alloc: check for malloc failure
---
src/malloc/mallocng/aligned_alloc.c | 3 +++
1 file changed, 3 insertions(+)
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);
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [musl] [PATCH] mallocng/aligned_alloc: check for malloc failure
2021-03-25 22:26 [musl] [PATCH] mallocng/aligned_alloc: check for malloc failure Dominic Chen
@ 2021-04-16 14:17 ` Rich Felker
0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2021-04-16 14:17 UTC (permalink / raw)
To: Dominic Chen; +Cc: musl
On Thu, Mar 25, 2021 at 06:26:04PM -0400, Dominic Chen wrote:
> 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.
>
> Thanks,
Thanks, applying!
Rich
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-16 14:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25 22:26 [musl] [PATCH] mallocng/aligned_alloc: check for malloc failure Dominic Chen
2021-04-16 14:17 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).