aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2017-03-05 18:55:46 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2017-03-05 18:55:46 +0100
commitd9e384e47f44ceadd5738cfaf885aa10260d1923 (patch)
treed057b422b91e31f78224b6ac28e48be2aa3a9cf1
parent9d166ef42cbc82e747ef5901a384796b10f95060 (diff)
downloadsciteco-d9e384e47f44ceadd5738cfaf885aa10260d1923.tar.gz
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().
-rw-r--r--src/memory.cpp6
1 files changed, 4 insertions, 2 deletions
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;
}