Re: [WIP/PATCH v4 5/8] for-each-ref: introduce 'ref_filter_clear_data()'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, May 30, 2015 at 7:53 PM, Karthik Nayak <karthik.188@xxxxxxxxx> 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.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;
> +}

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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]