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

Re: [PATCH] fetch: plug two leaks on error exit in store_updated_refs

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Oct 7, 2011, 06:59 UTC
Message-ID
<4E8EA33E.5020009@lsrfire.ath.cx>
In-Reply-To
<CALUzUxp4Eo7j=kM7YPJbj70-rwuyFK5V1mZZMY7vBwwPYWS6gQ@mail.gmail.com>
Am 07.10.2011 08:49, schrieb Tay Ray Chuan:
> How about reusing the function's cleanup calls, like this?
Yes, that's better.
Show 38 quoted lines
> -- >8 --
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index fc254b6..56267c4 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -423,8 +423,10 @@ static int store_updated_refs(const char
> *raw_url, const char *remote_name,
>  	else
>  		url = xstrdup("foreign");
> 
> -	if (check_everything_connected(ref_map, 0))
> -		return error(_("%s did not send all necessary objects\n"), url);
> +	if (check_everything_connected(ref_map, 0)) {
> +		rc = error(_("%s did not send all necessary objects\n"), url);
> +		goto abort;
> +	}
> 
>  	for (rm = ref_map; rm; rm = rm->next) {
>  		struct ref *ref = NULL;
> @@ -506,12 +508,15 @@ static int store_updated_refs(const char
> *raw_url, const char *remote_name,
>  				fprintf(stderr, " %s\n", note);
>  		}
>  	}
> -	free(url);
> -	fclose(fp);
> +
>  	if (rc & STORE_REF_ERROR_DF_CONFLICT)
>  		error(_("some local refs could not be updated; try running\n"
>  		      " 'git remote prune %s' to remove any old, conflicting "
>  		      "branches"), remote_name);
> +
> +abort:
> +	free(url);
> +	fclose(fp);
>  	return rc;
>  }
> 
Micro-nit: If you start the label with a space ("+ abort:") then the
code continues to play nice with git grep -W.
René
Previous: Tay Ray ChuanNext: Tay Ray Chuan
Message 4 of 5 in “Fix another file leak”
  1. Chris WilsonOct 7, 2011
  2. fetch: plug two leaks on error exit in store_updated_refsRené Scharfe, Oct 7, 2011
  3. Tay Ray ChuanOct 7, 2011
  4. René ScharfeOct 7, 2011
  5. fetch: plug two leaks on error exit in store_updated_refsTay Ray Chuan, Oct 7, 2011

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.