Loading...
--- libmalloc/libmalloc-521.120.7/src/nanov2_malloc.c
+++ libmalloc/libmalloc-474.0.13/src/nanov2_malloc.c
@@ -1517,7 +1517,9 @@
 	kern_return_t kr;
 	bitarray_t slots;
 
-	reader = reader_or_in_memory_fallback(reader, task);
+	if (!reader) {
+		reader = nano_common_default_reader;
+	}
 
 	kr = reader(task, zone_address, sizeof(nanozonev2_t), (void **)&nanozone);
 	if (kr) {
@@ -1641,7 +1643,7 @@
 							ranges[range_count].size = slot_size;
 							range_count++;
 						}
-						_free(slots);
+						free(slots);
 					}
 					if (range_count) {
 						// Notify the in-use pointers that we found.
@@ -1958,7 +1960,7 @@
 		malloc_statistics_t *stats)
 {
 	printer = printer ? printer : nanov2_null_printer;
-	reader = reader_or_in_memory_fallback(reader, task);
+	reader = !reader && task == mach_task_self() ? _malloc_default_reader : reader;
 
 	kern_return_t err;
 
@@ -3097,9 +3099,11 @@
 malloc_zone_t *
 nanov2_create_zone(malloc_zone_t *helper_zone, unsigned debug_flags)
 {
-	// Note: It is not necessary that nanov2_create_zone resets _malloc_engaged_nano
-	// if it is unable to enable the nanozone - functions that need to determine
-	// whether the nanozone is preset should test initial_nano_zone.
+	// Note: It is important that nanov2_create_zone resets _malloc_engaged_nano
+	// if it is unable to enable the nanozone (and chooses not to abort). As
+	// several functions rely on _malloc_engaged_nano to determine if they
+	// should manipulate the nanozone, and these should not run if we failed
+	// to create the zone.
 	MALLOC_ASSERT(_malloc_engaged_nano == NANO_V2);
 
 	// Get memory for the zone and disable Nano if we fail.