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

Re: [PATCH] * remote.c (valid_fetch_refspec): remove useless if-before-free test

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 21, 2008, 00:16 UTC
Message-ID
<7vr68jmdd2.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<pI8EXbuWhkm4pM0AaaTAPQQYBeFSffOSzCiM4NfNHKomivEcfUfShA@cipher.nrlssc.navy.mil>
Brandon Casey <casey@nrlssc.navy.mil> writes:
Show 23 quoted lines
> Maybe we should also begin the process of not leaking memory here...
>
> diff --git a/remote.c b/remote.c
> index 7f2897b..984ad1b 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -449,6 +449,20 @@ static int verify_refname(char *name, int is_glob)
> 	return result;
>  }
>  
> +void free_refspecs(struct refspec *refspec, int nr_refspec)
> +{
> +	int i;
> +
> +	if (!refspec)
> +		return;
> +
> +	for (i = 0; i < nr_refspec; i++) {
> +		free(refspec[i].src);
> +		free(refspec[i].dst);
> +	}
> +	free(refspec);
> +}

Are you sure all the codepaths that stuff refspec[].{src,dst} give freeable pointer? E.g. if anybody splits a originally single string "refs/heads/foo:refs/remotes/origin/foo" into two by replacing the colon with NUL and pointing the halves, and/or such string came from argv[] without strdup(), I'd imagine free() would not like you very much.

I didn't look, though.
Previous: Brandon CaseyNext: Brandon Casey
Message 5 of 8 in “* remote.c (valid_fetch_refspec): remove useless if-before-free test”
  1. * remote.c (valid_fetch_refspec): remove useless if-before-free testJim Meyering, Aug 19, 2008
  2. Alex RiesenAug 20, 2008
  3. Jim MeyeringAug 20, 2008
  4. Brandon CaseyAug 20, 2008
  5. Junio C HamanoAug 21, 2008
  6. Brandon CaseyAug 21, 2008
  7. Junio C HamanoAug 21, 2008
  8. remote.c: add a function for deleting a refspec array and use it (twice)Brandon Casey, Aug 22, 2008

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.