diff array.c @ 39:337110e7240a

Pass the size to free; it makes debug checking easier.
author David A. Holland
date Sat, 30 Mar 2013 21:17:47 -0400
parents b156910b59b2
children
line wrap: on
line diff
--- a/array.c	Sat Mar 30 21:02:25 2013 -0400
+++ b/array.c	Sat Mar 30 21:17:47 2013 -0400
@@ -47,7 +47,7 @@
 array_destroy(struct array *a)
 {
 	array_cleanup(a);
-	dofree(a);
+	dofree(a, sizeof(*a));
 }
 
 void
@@ -61,7 +61,7 @@
 array_cleanup(struct array *a)
 {
 	arrayassert(a->num == 0);
-	dofree(a->v);
+	dofree(a->v, a->max * sizeof(a->v[0]));
 #ifdef ARRAYS_CHECKED
 	a->v = NULL;
 #endif
@@ -78,7 +78,8 @@
 		while (num > newmax) {
 			newmax = newmax ? newmax*2 : 4;
 		}
-		newptr = dorealloc(a->v, newmax*sizeof(*a->v));
+		newptr = dorealloc(a->v, a->max * sizeof(a->v[0]),
+				   newmax * sizeof(a->v[0]));
 		a->v = newptr;
 		a->max = newmax;
 	}