From c897c456d75c363ef4343ae50613e72e3146d08a Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Tue, 29 May 2018 14:47:20 +0200 Subject: [PATCH] lib: make allocators work for allocation sizes of 0 Fixes: #2155 Signed-off-by: Christian Franke --- lib/memory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/memory.c b/lib/memory.c index be8b100ba7..318c381bf5 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -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); -- 2.39.5