aboutsummaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-10-15 18:34:34 -0400
committerJunio C Hamano <gitster@pobox.com>2014-10-16 10:10:37 -0700
commit46be823124bb6a6ff0e06dc19c327b599ed97c72 (patch)
tree3cd5b02dcf8316c8416ae850771d2fdb159e7d42 /object.c
parent68f492359e29bbdf633201406d0646deee2b298c (diff)
downloadgit-46be823124bb6a6ff0e06dc19c327b599ed97c72.tar.gz
git-46be823124bb6a6ff0e06dc19c327b599ed97c72.tar.xz
object_array: add a "clear" function
There's currently no easy way to free the memory associated with an object_array (and in most cases, we simply leak the memory in a rev_info's pending array). Let's provide a helper to make this easier to handle. We can make use of it in list-objects.c, which does the same thing by hand (but fails to free the "name" field of each entry, potentially leaking memory). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object.c')
-rw-r--r--object.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/object.c b/object.c
index 60f486463..6aeb1bbbe 100644
--- a/object.c
+++ b/object.c
@@ -383,6 +383,16 @@ void object_array_filter(struct object_array *array,
array->nr = dst;
}
+void object_array_clear(struct object_array *array)
+{
+ int i;
+ for (i = 0; i < array->nr; i++)
+ object_array_release_entry(&array->objects[i]);
+ free(array->objects);
+ array->objects = NULL;
+ array->nr = array->alloc = 0;
+}
+
/*
* Return true iff array already contains an entry with name.
*/