Re: [PATCH 2/3] bundle.c: fix memory leak

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

 



Stefan Beller <sbeller@xxxxxxxxxx> writes:

> There was one continue statement without an accompanying `free(ref)`.
> Instead of adding that, replace all the free&&continue with a goto
> just after writing the refs, where we'd do the free anyway and then
> reloop.
>
> Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
> ---
>  bundle.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/bundle.c b/bundle.c
> index 2e2dbd5..f732c92 100644
> --- a/bundle.c
> +++ b/bundle.c
> @@ -334,7 +334,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
>  		if (e->item->flags & UNINTERESTING)
>  			continue;
>  		if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
> -			continue;
> +			goto skip_write_ref;

Thanks.

I briefly wondered if we need to initialize ref=NULL for this to
work, because dwim_ref() does not need to clear ref when it says
"nothing matches", but the function actually clears it upfront, so
we should be OK.

> ...
> @@ -397,6 +395,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
>  		write_or_die(bundle_fd, " ", 1);
>  		write_or_die(bundle_fd, display_ref, strlen(display_ref));
>  		write_or_die(bundle_fd, "\n", 1);
> + skip_write_ref:
>  		free(ref);
>  	}
--
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]