Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
for-each-ref: introduce 'ref_array_clear()'
author
Karthik Nayak
<karthik.188@gmail.com>
Sat, 13 Jun 2015 19:37:23 +0000
(
01:07
+0530)
committer
Junio C Hamano
<gitster@pobox.com>
Mon, 15 Jun 2015 18:48:08 +0000
(11:48 -0700)
Introduce and implement 'ref_array_clear()' which will free
all allocated memory for 'ref_array'.
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/for-each-ref.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
215b565
)
diff --git
a/builtin/for-each-ref.c
b/builtin/for-each-ref.c
index 822838a91198d71c2a08e29ce9ef8e04579c1f95..bb83f7a952331d8a44089966ed630a77fd535c07 100644
(file)
--- a/
builtin/for-each-ref.c
+++ b/
builtin/for-each-ref.c
@@
-927,6
+927,26
@@
static int grab_single_ref(const char *refname, const struct object_id *oid,
return 0;
}
return 0;
}
+/* Free memory allocated for a ref_array_item */
+static void free_array_item(struct ref_array_item *item)
+{
+ free((char *)item->symref);
+ free(item->refname);
+ free(item);
+}
+
+/* Free all memory allocated for ref_array */
+void ref_array_clear(struct ref_array *array)
+{
+ int i;
+
+ for (i = 0; i < array->nr; i++)
+ free_array_item(array->items[i]);
+ free(array->items);
+ array->items = NULL;
+ array->nr = array->alloc = 0;
+}
+
static int cmp_ref_sort(struct ref_sort *s, struct ref_array_item *a, struct ref_array_item *b)
{
struct atom_value *va, *vb;
static int cmp_ref_sort(struct ref_sort *s, struct ref_array_item *a, struct ref_array_item *b)
{
struct atom_value *va, *vb;
@@
-1157,5
+1177,6
@@
int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
maxcount = ref_cbdata.array.nr;
for (i = 0; i < maxcount; i++)
show_ref(ref_cbdata.array.items[i], format, quote_style);
maxcount = ref_cbdata.array.nr;
for (i = 0; i < maxcount; i++)
show_ref(ref_cbdata.array.items[i], format, quote_style);
+ ref_array_clear(&ref_cbdata.array);
return 0;
}
return 0;
}