lib: make allocators work for allocation sizes of 0

Fixes: #2155
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
This commit is contained in:
Christian Franke 2018-05-29 14:47:20 +02:00
parent bdb53116de
commit c897c456d7

View File

@ -52,7 +52,10 @@ static inline void mt_count_free(struct memtype *mt)
static inline void *mt_checkalloc(struct memtype *mt, void *ptr, size_t size)
{
if (__builtin_expect(ptr == NULL, 0)) {
memory_oom(size, mt->name);
if (size) {
/* malloc(0) is allowed to return NULL */
memory_oom(size, mt->name);
}
return NULL;
}
mt_count_alloc(mt, size);