Loading...
--- libmalloc/libmalloc-409.81.2/src/malloc.c
+++ libmalloc/libmalloc-409.40.6/src/malloc.c
@@ -150,7 +150,7 @@
 static const char zero_on_free_sample_period_boot_arg[] = "malloc_zero_on_free_sample_period";
 
 MALLOC_NOEXPORT
-malloc_zero_policy_t malloc_zero_policy = MALLOC_ZERO_POLICY_DEFAULT;
+bool malloc_zero_on_free = MALLOC_ZERO_ON_FREE_ENABLED_DEFAULT;
 
 static const char zero_on_free_enabled_boot_arg[] = "malloc_zero_on_free_enabled";
 
@@ -171,8 +171,8 @@
 typedef void * (*dlopen_t) (const char * __path, int __mode);
 typedef void * (*dlsym_t) (void * __handle, const char * __symbol);
 
-static dlopen_t LIBMALLOC_FUNCTION_PTRAUTH(_dlopen) = NULL;
-static dlsym_t LIBMALLOC_FUNCTION_PTRAUTH(_dlsym) = NULL;
+static dlopen_t _dlopen = NULL;
+static dlsym_t _dlsym = NULL;
 #else
 #define _dlopen(...) NULL
 #define _dlsym(...) NULL
@@ -278,7 +278,7 @@
 		const char *endp;
 		long value = malloc_common_convert_to_long(flag, &endp);
 		if (!*endp && (value == 0 || value == 1)) {
-			malloc_zero_policy = value ? MALLOC_ZERO_ON_FREE : MALLOC_ZERO_NONE;
+			malloc_zero_on_free = value;
 		} else {
 			malloc_report(ASL_LEVEL_ERR,
 					"malloc_zero_on_free_enabled must be 0 or 1 - ignored.\n");
@@ -397,11 +397,9 @@
 
 #if CONFIG_FEATUREFLAGS_SIMPLE
 	bool zero_on_free_feature_enabled = os_feature_enabled_simple(libmalloc,
-			ZeroOnFree, MALLOC_ZERO_POLICY_DEFAULT == MALLOC_ZERO_ON_FREE);
-	bool policy_is_zero_on_free = (malloc_zero_policy == MALLOC_ZERO_ON_FREE);
-	if (zero_on_free_feature_enabled != policy_is_zero_on_free) {
-		malloc_zero_policy = zero_on_free_feature_enabled ?
-				MALLOC_ZERO_ON_FREE : MALLOC_ZERO_NONE;
+			ZeroOnFree, MALLOC_ZERO_ON_FREE_ENABLED_DEFAULT);
+	if (zero_on_free_feature_enabled != malloc_zero_on_free) {
+		malloc_zero_on_free = zero_on_free_feature_enabled;
 	}
 #endif
 
@@ -1207,13 +1205,11 @@
 #endif
 
 #if TARGET_OS_OSX
-	// rdar://99288027
 	if (!dyld_program_sdk_at_least(dyld_platform_version_macOS_13_0)) {
-		if (malloc_zero_policy == MALLOC_ZERO_ON_FREE) {
-			malloc_zero_policy = MALLOC_ZERO_ON_ALLOC;
-		}
-	}
-#else // TARGET_OS_OSX
+		if (malloc_zero_on_free) {
+			malloc_zero_on_free = false;
+		}
+	}
 #endif // TARGET_OS_OSX
 
 	/*
@@ -1516,20 +1512,9 @@
 		const char *endp;
 		long value = malloc_common_convert_to_long(flag, &endp);
 		if (!*endp && endp != flag && (value == 0 || value == 1)) {
-			malloc_zero_policy = value ? MALLOC_ZERO_ON_FREE : MALLOC_ZERO_NONE;
+			malloc_zero_on_free = (value == 1);
 		} else {
 			malloc_report(ASL_LEVEL_ERR, "MallocZeroOnFree must be 0 or 1.\n");
-		}
-	}
-
-	flag = getenv("MallocZeroOnAlloc");
-	if (flag) {
-		const char *endp;
-		long value = malloc_common_convert_to_long(flag, &endp);
-		if (!*endp && endp != flag && (value == 0 || value == 1)) {
-			malloc_zero_policy = value ? MALLOC_ZERO_ON_ALLOC : MALLOC_ZERO_NONE;
-		} else {
-			malloc_report(ASL_LEVEL_ERR, "MallocZeroOnAlloc must be 0 or 1.\n");
 		}
 	}
 
@@ -1564,8 +1549,6 @@
 				"  MallocCorruptionAbort is always set on 64-bit processes\n"
 				"- MallocErrorAbort to abort on any malloc error, including out of memory\n"\
 				"- MallocTracing to emit kdebug trace points on malloc entry points\n"\
-				"- MallocZeroOnFree to enable or disable zero-on-free behavior (for debugging only)\n"\
-				"- MallocCheckZeroOnFreeCorruption to enable zero-on-free corruption detection\n"\
 				"- MallocHelp - this help!\n");
 	}
 }
@@ -2883,7 +2866,7 @@
 void
 malloc_zero_on_free_disable(void)
 {
-	malloc_zero_policy = MALLOC_ZERO_NONE;
+	malloc_zero_on_free = false;
 }
 
 /*****************	OBSOLETE ENTRY POINTS	********************/