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
Brandon Casey <casey@nrlssc.navy.mil>
Date
Aug 21, 2008, 00:33 UTC
Message-ID
<aS-Yl0OfC9_Ks79Dz2qAKZMrGX1F6_mTNtSFuB45LyarCC5Zmb8agA@cipher.nrlssc.navy.mil>
In-Reply-To
<7vr68jmdd2.fsf@gitster.siamese.dyndns.org>
Junio C Hamano wrote:
Show 28 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
> 
>> 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?

remote.c:parse_refspec_internal() always does. This function is the producer of the refspec that is being passed to free_refspecs() in the two places where the patch called it.

The code paths for each additionally use of free_refspecs would have to check that it is safe. Perhaps a comment is in order.

If you don't think we're ready for free_refspecs we can still call free() manually in the two places I called free_refspecs.

-brandon
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 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.