diff options
author | Mike Reed <reed@google.com> | 2018-01-05 11:20:10 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-05 21:29:35 +0000 |
commit | 8dc8dbc8211e7b0245a6e7db911265efbe0fccaf (patch) | |
tree | f112c74f618a536e86a80d9d657b804a039f3f54 /src/ports/SkMemory_mozalloc.cpp | |
parent | f21b32ccd7bd174ce647078854b2314f8b64d94c (diff) |
begin cleanup of malloc porting layer
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.
Bug:508641
Change-Id: I322f1e6ed91113467e0fdb12c91c3dad33d890c8
Reviewed-on: https://skia-review.googlesource.com/90940
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Stephan Altmueller <stephana@google.com>
Diffstat (limited to 'src/ports/SkMemory_mozalloc.cpp')
-rw-r--r-- | src/ports/SkMemory_mozalloc.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/ports/SkMemory_mozalloc.cpp b/src/ports/SkMemory_mozalloc.cpp index bf5971ba07..e13b94612a 100644 --- a/src/ports/SkMemory_mozalloc.cpp +++ b/src/ports/SkMemory_mozalloc.cpp @@ -22,22 +22,28 @@ void sk_out_of_memory(void) { mozalloc_handle_oom(0); } -void* sk_malloc_throw(size_t size) { - return sk_malloc_flags(size, SK_MALLOC_THROW); +void sk_free(void* p) { + free(p); } void* sk_realloc_throw(void* addr, size_t size) { return moz_xrealloc(addr, size); } -void sk_free(void* p) { - free(p); -} - void* sk_malloc_flags(size_t size, unsigned flags) { +#ifndef SK_SUPPORT_LEGACY_MALLOC_PORTING_LAYER + if (flags & SK_MALLOC_ZERO_INITIALIZE) { + return (flags & SK_MALLOC_THROW) ? moz_xcalloc(size, 1) : calloc(size, 1); + } +#endif return (flags & SK_MALLOC_THROW) ? moz_xmalloc(size) : malloc(size); } +#ifdef SK_SUPPORT_LEGACY_MALLOC_PORTING_LAYER +void* sk_malloc_throw(size_t size) { + return sk_malloc_flags(size, SK_MALLOC_THROW); +} + void* sk_calloc(size_t size) { return calloc(size, 1); } @@ -45,3 +51,5 @@ void* sk_calloc(size_t size) { void* sk_calloc_throw(size_t size) { return moz_xcalloc(size, 1); } +#endif + |