Re: [PATCH 14/22] shallow: fix leaking members of `struct shallow_info`

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

 



Patrick Steinhardt <ps@xxxxxx> writes:

> We do not free several struct members in `clear_shallow_info()`. Fix
> this to plug the resulting leaks.
>
> Signed-off-by: Patrick Steinhardt <ps@xxxxxx>
> ---
>  shallow.c               | 9 +++++++++
>  t/t5538-push-shallow.sh | 1 +
>  2 files changed, 10 insertions(+)
>
> diff --git a/shallow.c b/shallow.c
> index 7e0ee96ead9..dcebc263d70 100644
> --- a/shallow.c
> +++ b/shallow.c
> @@ -489,6 +489,15 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
>  
>  void clear_shallow_info(struct shallow_info *info)
>  {
> +	if (info->used_shallow) {
> +		for (size_t i = 0; i < info->shallow->nr; i++)
> +			free(info->used_shallow[i]);
> +		free(info->used_shallow);
> +	}
> +
> +	free(info->need_reachability_test);
> +	free(info->reachable);
> +	free(info->shallow_ref);
>  	free(info->ours);
>  	free(info->theirs);
>  }

Recently was agreed in the CodingGuidelines `S_clear()` functions do a
`S_release()` + `S_init()`. I see we're not initializing the struct for
future use (i.e. we don't reset the `nr_*` fields to 0). But we cannot
really do an init, because that would be calling
`prepare_shallow_info()`, which allocates new memory. So would it be
worth to rename this function to `release_shallow_info()`?

--
Toon




[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]

  Powered by Linux