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.