Re: [WIP/PATCH v4 5/8] for-each-ref: introduce 'ref_filter_clear_data()'
- From
Christian Couder <christian.couder@gmail.com>
- Date
- May 31, 2015, 07:38 UTC
- Message-ID
- <CAP8UFD341nSMLvsXynbDfQ4kLoddBL5rhXrhyePTT0LHACzfuQ@mail.gmail.com>
- In-Reply-To
- <1433008411-8550-5-git-send-email-karthik.188@gmail.com>
On Sat, May 30, 2015 at 7:53 PM, Karthik Nayak <karthik.188@gmail.com> wrote:
Show 30 quoted lines
> 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@gmail.com>
> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
> Signed-off-by: Karthik Nayak <karthik.188@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.