mailing list of musl libc
 help / color / mirror / Atom feed
* [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

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ http://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/musl/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git