Merge "Avoid heap initialization for skia allocations." am: ddec45d4f3

Original change: https://android-review.googlesource.com/c/platform/external/skia/+/1431544

Change-Id: I4e1aaf9b66b63c5ac5c8c9f9c080b1f538917ee6
diff --git a/src/ports/SkMemory_malloc.cpp b/src/ports/SkMemory_malloc.cpp
index 89e2109..2952632 100644
--- a/src/ports/SkMemory_malloc.cpp
+++ b/src/ports/SkMemory_malloc.cpp
@@ -68,7 +68,21 @@
     if (flags & SK_MALLOC_ZERO_INITIALIZE) {
         p = calloc(size, 1);
     } else {
+#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(__BIONIC__)
+        /* TODO: After b/169449588 is fixed, we will want to change this to restore
+         *       original behavior instead of always disabling the flag.
+         * TODO: After b/158870657 is fixed and scudo is used globally, we can assert when an
+         *       an error is returned.
+         */
+        // malloc() generally doesn't initialize its memory and that's a huge security hole,
+        // so Android has replaced its malloc() with one that zeros memory,
+        // but that's a huge performance hit for HWUI, so turn it back off again.
+        (void)mallopt(M_THREAD_DISABLE_MEM_INIT, 1);
+#endif
         p = malloc(size);
+#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(__BIONIC__)
+        (void)mallopt(M_THREAD_DISABLE_MEM_INIT, 0);
+#endif
     }
     if (flags & SK_MALLOC_THROW) {
         return throw_on_failure(size, p);