Introduce and implement 'ref_filter_clear_data()' which will free all allocated memory for 'ref_filter_cbdata' and its underlying array of 'ref_array_item'. Mentored-by: Christian Couder <christian.couder@xxxxxxxxx> Mentored-by: Matthieu Moy <matthieu.moy@xxxxxxxxxxxxxxx> Signed-off-by: Karthik Nayak <karthik.188@xxxxxxxxx> --- builtin/for-each-ref.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index ef54c90..f896e1c 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -907,6 +907,18 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f return 0; } +/* Free all memory allocated for ref_filter_cbdata */ +void ref_filter_clear_data(struct ref_filter_cbdata *ref_cbdata) +{ + int i; + + for (i = 0; i < ref_cbdata->array.nr; i++) + free(ref_cbdata->array.items[i]); + free(ref_cbdata->array.items); + ref_cbdata->array.items = NULL; + ref_cbdata->array.nr = ref_cbdata->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; @@ -1137,5 +1149,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); + ref_filter_clear_data(&ref_cbdata); return 0; } -- 2.4.2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html