Module Name:    src
Committed By:   ad
Date:           Sat Oct 14 19:38:51 UTC 2023

Modified Files:
        src/lib/libc/stdlib: jemalloc.c

Log Message:
Cherry pick a fix from FreeBSD:

commit 80bc871bdd4a8254ce19a65a54c8c918dd3ddd11
Author: Konstantin Belousov <k...@freebsd.org>
Date:   Sat Sep 12 18:16:46 2009 +0000

    MFC r196861:
    Handle zero size for posix_memalign. Return NULL or unique address
    according to the 'V' option.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.61 src/lib/libc/stdlib/jemalloc.c:1.62
--- src/lib/libc/stdlib/jemalloc.c:1.61	Sat Oct 14 19:37:24 2023
+++ src/lib/libc/stdlib/jemalloc.c	Sat Oct 14 19:38:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.61 2023/10/14 19:37:24 ad Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.62 2023/10/14 19:38:51 ad Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans <jas...@freebsd.org>.
@@ -111,7 +111,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */
-__RCSID("$NetBSD: jemalloc.c,v 1.61 2023/10/14 19:37:24 ad Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.62 2023/10/14 19:38:51 ad Exp $");
 
 #include "namespace.h"
 #include <sys/mman.h>
@@ -3632,6 +3632,15 @@ posix_memalign(void **memptr, size_t ali
 			goto RETURN;
 		}
 
+		if (size == 0) {
+			if (NOT_OPT(sysv))
+				size = 1;
+			else {
+				result = NULL;
+				ret = 0;
+				goto RETURN;
+			}
+		}
 		result = ipalloc(alignment, size);
 	}
 

Reply via email to