On Sat, May 30, 2015 at 7:53 PM, Karthik Nayak <karthik....@gmail.com> wrote:
> 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.cou...@gmail.com>
> Mentored-by: Matthieu Moy <matthieu....@grenoble-inp.fr>
> Signed-off-by: Karthik Nayak <karthik....@gmail.com>
> ---
>  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;
> +}

As this is clearing the array only, it would be better to have it in a
ref_array_clear() function.
There are already argv_array_clear() and sha1_array_clear() by the way.
And maybe if many such ref_array functions are created and start being
used elsewhere we can easily move everything into new ref-array.{c,h}
files.

Thanks,
Christian.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to