git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 11, 2015, 03:57 UTC
Message-ID
<xmqqegowuqxh.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1426031508-7575-1-git-send-email-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 20 quoted lines
> 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@google.com>
> ---
>  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.

Show 8 quoted lines
> ...
> @@ -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);
>  	}
Previous: Stefan BellerNext: Stefan Beller
Message 7 of 13 in “connect.c: Fix memory leak”
  1. 1/3 connect.c: Fix memory leakStefan Beller, Mar 9, 2015
  2. 2/3 bundle.c: fix memory leakStefan Beller, Mar 9, 2015
  3. Junio C HamanoMar 10, 2015
  4. Stefan BellerMar 10, 2015
  5. Junio C HamanoMar 10, 2015
  6. 2/3 bundle.c: fix memory leakStefan Beller, Mar 10, 2015
  7. Junio C HamanoMar 11, 2015
  8. 3/3 builtin/help.c: fix memory leakStefan Beller, Mar 9, 2015
  9. Junio C HamanoMar 10, 2015
  10. Stefan BellerMar 10, 2015
  11. Junio C HamanoMar 11, 2015
  12. Torsten BögershausenMar 9, 2015
  13. Junio C HamanoMar 10, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.