From: Christian Franke Date: Tue, 29 May 2018 12:47:20 +0000 (+0200) Subject: lib: make allocators work for allocation sizes of 0 X-Git-Tag: frr-4.0.1~10^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=e64c3d2cb0218a85c8d9434f4a7e8202d7692234;p=mirror%2Ffrr.git lib: make allocators work for allocation sizes of 0 Fixes: #2155 Signed-off-by: Christian Franke --- diff --git a/lib/memory.c b/lib/memory.c index c684c7605c..c66da828c7 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -51,7 +51,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);