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

Re: [PATCH] git-mv: Fix error with multiple sources.

From
DRDavid Rydh <dary@math.berkeley.edu>
Date
Jan 22, 2010, 16:41 UTC
Message-ID
<28E55A63-C40D-4C5D-906F-742AC6FC9A88@math.berkeley.edu>
In-Reply-To
<7v8wbqbs26.fsf@alter.siamese.dyndns.org>
On Jan 21, 2010, at 9:57 PM, Junio C Hamano wrote:
Show 20 quoted lines
>> diff --git a/setup.c b/setup.c
>> index 710e2f3..80cf535 100644
>> --- a/setup.c
>> +++ b/setup.c
>> @@ -132,8 +132,8 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
>> 		return NULL;
>> 
>> 	if (!entry) {
>> -		static const char *spec[2];
>> -		spec[0] = prefix;
>> +		const char **spec = xmalloc(sizeof(char *) * 2);
>> +		spec[0] = xstrdup(prefix);
>> 		spec[1] = NULL;
>> 		return spec;
>> 	}
> 
> I don't understand this change.  Because elements of returned pathspec
> from this function are often simply the pathspec argument itself (which in
> turn is often argv[] of the calling program), and other times allocated by
> this function, the callers are never going to free() them.
The xstrdup of prefix is for good measure. The important change is the removal of the static spec-array. Two invocations of get_pathspec with different prefixes could invalidate the contents of a pathspec in use.
When called with a non-empty pathspec, all the entries are allocated so I think it is reasonable to allocate them in the degenerate case as well. My impression of the git-code is that it is leaking quite a bit when it comes to strings anyway.
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 10 in “git-mv: Fix error with multiple sources.”
  1. git-mv: Fix error with multiple sources.David Rydh, Jan 21, 2010
  2. Junio C HamanoJan 22, 2010
  3. David RydhJan 22, 2010
  4. Junio C HamanoJan 22, 2010
  5. David RydhJan 22, 2010
  6. Junio C HamanoJan 22, 2010
  7. Matthieu MoyJan 22, 2010
  8. Johannes SixtJan 22, 2010
  9. David RydhJan 22, 2010
  10. Johannes SixtJan 22, 2010

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.