RESTRICT AUTOMERGE: Cherry-pick "begin cleanup of malloc porting layer"

Bug: 78354855
Test: Not feasible

Original description:
1. Merge some of the allocators into sk_malloc_flags by redefining a flag to mean zero-init
2. Add more private helpers to simplify our call-sites (and handle some overflow mul checks)
3. The 2-param helpers rely on the saturating SkSafeMath::Mul to pass max_size_t as the request,
which should always fail.

chromium: 508641
Commit-Queue: Mike Reed <>
Reviewed-by: Robert Phillips <>
Reviewed-by: Stephan Altmueller <>

- include/private/SkMalloc.h
Simply removed the old definitions of SK_MALLOC_TEMP and SK_MALLOC_THROW.
- public.bzl
- src/codec/SkIcoCodec.cpp
Drop a change where we were not using malloc yet.
- src/codec/SkBmpBaseCodec.cpp
- src/core/SkBitmapCache.cpp
These files weren't yet using malloc (and SkBmpBaseCodec hadn't been
factored out).
- src/core/SkMallocPixelRef.cpp
These were still using New rather than Make (return raw pointer). Leave
them unchanged, as sk_malloc_flags is still valid.
- src/lazy/SkDiscardableMemoryPool.cpp
Leave this unchanged; sk_malloc_flags is still valid

In addition, pull in SkSafeMath.h, which was originally introduced in This is required
for the new sk_malloc calls.

Also pull in SkSafeMath::Add and SkSafeMath::Mul, introduced in

Also add SK_MaxSizeT, which the above depends on, introduced in

Also, modify NewFromStream to use sk_malloc_canfail, matching pi and
avoiding a build break

Change-Id: Ib320484673a865460fc1efb900f611209e088edb
(cherry picked from commit a12cc3e14ea6734c7efe76aa6a19239909830b28)
15 files changed