summaryrefslogtreecommitdiffstats
path: root/lib/memory.c
diff options
context:
space:
mode:
authorChris Hall <chris.hall.list.highwayman.com>2010-07-23 20:27:11 +0200
committerPaul Jakma <paul@quagga.net>2011-03-21 12:09:13 +0100
commitcca85d27a59c31e1b20e4c4adc7d9bb57606e584 (patch)
tree2330a624f08c04a4125dc3153c97d93361c2da85 /lib/memory.c
parentMerge paul/ospfd/201012-review ospfd and lib/ fixes and performance improvements (diff)
downloadfrr-cca85d27a59c31e1b20e4c4adc7d9bb57606e584.tar.xz
frr-cca85d27a59c31e1b20e4c4adc7d9bb57606e584.zip
lib: Fix accounting of memory
* 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.
Diffstat (limited to 'lib/memory.c')
-rw-r--r--lib/memory.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/memory.c b/lib/memory.c
index 4bac31dbb..4090fd901 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -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);
+ }
}
/*