From d9e384e47f44ceadd5738cfaf885aa10260d1923 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 5 Mar 2017 18:55:46 +0100 Subject: memory limiting: libc malloc() and realloc() can return NULL * shouldn't make much of a difference, since we're in deep trouble when they return NULL, but the wrappers should be transparent instead of crashing in malloc_usable_size(). --- src/memory.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/memory.cpp') diff --git a/src/memory.cpp b/src/memory.cpp index 98a2ac0..e989210 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -81,7 +81,8 @@ malloc(size_t size) libc_malloc = (malloc_cb)dlsym(RTLD_NEXT, "malloc"); ret = libc_malloc(size); - memory_usage += malloc_usable_size(ret); + if (G_LIKELY(ret)) + memory_usage += malloc_usable_size(ret); return ret; } @@ -98,7 +99,8 @@ realloc(void *ptr, size_t size) if (ptr) memory_usage -= malloc_usable_size(ptr); ptr = libc_realloc(ptr, size); - memory_usage += malloc_usable_size(ptr); + if (G_LIKELY(ptr)) + memory_usage += malloc_usable_size(ptr); return ptr; } -- cgit v1.2.3