Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: base/process/memory_mac.mm

Issue 55333002: Make possible to check memory allocations inside chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes inspired by trybots Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/memory_linux.cc ('k') | base/process/memory_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/memory_mac.mm
diff --git a/base/process/memory_mac.mm b/base/process/memory_mac.mm
index 3e281cd8e3ca355ae5b2eb0581acb1c3bafbb71b..6cf1297b26f01f680f4da4917bf175259122a2db 100644
--- a/base/process/memory_mac.mm
+++ b/base/process/memory_mac.mm
@@ -502,26 +502,42 @@ id oom_killer_allocWithZone(id self, SEL _cmd, NSZone* zone)
} // namespace
-void* UncheckedMalloc(size_t size) {
+bool UncheckedMalloc(size_t size, void** result) {
if (g_old_malloc) {
#if ARCH_CPU_32_BITS
ScopedClearErrno clear_errno;
ThreadLocalBooleanAutoReset flag(g_unchecked_alloc.Pointer(), true);
#endif // ARCH_CPU_32_BITS
- return g_old_malloc(malloc_default_zone(), size);
+ *result = g_old_malloc(malloc_default_zone(), size);
+ } else {
+ *result = malloc(size);
}
- return malloc(size);
+
+ return *result != NULL;
}
-void* UncheckedCalloc(size_t num_items, size_t size) {
+bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
if (g_old_calloc) {
#if ARCH_CPU_32_BITS
ScopedClearErrno clear_errno;
ThreadLocalBooleanAutoReset flag(g_unchecked_alloc.Pointer(), true);
#endif // ARCH_CPU_32_BITS
- return g_old_calloc(malloc_default_zone(), num_items, size);
+ *result = g_old_calloc(malloc_default_zone(), num_items, size);
+ } else {
+ *result = calloc(num_items, size);
}
- return calloc(num_items, size);
+
+ return *result != NULL;
+}
+
+void* UncheckedMalloc(size_t size) {
+ void* address;
+ return UncheckedMalloc(size, &address) ? address : NULL;
+}
+
+void* UncheckedCalloc(size_t num_items, size_t size) {
+ void* address;
+ return UncheckedCalloc(num_items, size, &address) ? address : NULL;
}
void EnableTerminationOnOutOfMemory() {
« no previous file with comments | « base/process/memory_linux.cc ('k') | base/process/memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698