]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Fix accounting of memory
authorChris Hall <chris.hall.list.highwayman.com>
Fri, 23 Jul 2010 18:27:11 +0000 (11:27 -0700)
committerPaul Jakma <paul@quagga.net>
Mon, 21 Mar 2011 11:09:13 +0000 (11:09 +0000)
* lib/memory.c: (zrealloc) If is called with NULL pointer then it should
  increment allocations because it behaves the same as zmalloc.

  (zfree) is called with NULL pointer, it does nothing therefore allocation
  count should not change.

lib/memory.c

index 4bac31dbb45ba87ef22268d9336f639fee25779c..4090fd901f2a27b0b6f87cd5253623ffe21a582e 100644 (file)
@@ -111,6 +111,9 @@ zrealloc (int type, void *ptr, size_t size)
   memory = realloc (ptr, size);
   if (memory == NULL)
     zerror ("realloc", type, size);
+  if (ptr == NULL)
+    alloc_inc (type);
+
   return memory;
 }
 
@@ -123,8 +126,11 @@ zrealloc (int type, void *ptr, size_t size)
 void
 zfree (int type, void *ptr)
 {
-  alloc_dec (type);
-  free (ptr);
+  if (ptr != NULL)
+    {
+      alloc_dec (type);
+      free (ptr);
+    }
 }
 
 /*