Loading...
gen/scalable_malloc.c Libc-391 Libc-391.2.6
--- Libc/Libc-391/gen/scalable_malloc.c
+++ Libc/Libc-391.2.6/gen/scalable_malloc.c
@@ -603,7 +603,7 @@
     boolean_t		add_guard_pages = debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES;
     size_t		allocation_size = round_page(size);
     size_t		delta;
-    
+
     if (align) add_guard_pages = 0; // too cumbersome to deal with that
     if (!allocation_size) allocation_size = 1 << vm_page_shift;
     if (add_guard_pages) allocation_size += 2 * (1 << vm_page_shift);
@@ -3075,7 +3075,10 @@
     } else {
 	// large or huge
 	num_pages = round_page(size) >> vm_page_shift;
-	ptr = large_and_huge_malloc(szone, num_pages);
+	if (num_pages == 0)	/* Overflowed */
+		ptr = 0;
+	else
+		ptr = large_and_huge_malloc(szone, num_pages);
     }
 #if DEBUG_MALLOC
     if (LOG(szone, ptr))