]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: make allocators work for allocation sizes of 0
authorChristian Franke <chris@opensourcerouting.org>
Tue, 29 May 2018 12:47:20 +0000 (14:47 +0200)
committerChristian Franke <chris@opensourcerouting.org>
Tue, 29 May 2018 12:47:20 +0000 (14:47 +0200)
Fixes: #2155
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
lib/memory.c

index c684c7605c00b9063b9390fbc45adb89ecb41e49..c66da828c775d494593dca969e4c1d1f3e8c6f51 100644 (file)
@@ -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);