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

Re: [PATCH] mailmap: fix check for freeing memory

From
Stefan Beller <stefanbeller@googlemail.com>
Date
Aug 20, 2013, 14:17 UTC
Message-ID
<52137A63.3010609@googlemail.com>
In-Reply-To
<878uzw7a6l.fsf@linux-k42r.v.cablecom.net>
On 08/20/2013 03:40 PM, Thomas Rast wrote:
Show 14 quoted lines
> Stefan Beller <stefanbeller@googlemail.com> writes:
> 
>> The condition as it is written in that line was most likely intended to
>> check for the pointer passed to free(), rather than checking for the
>> 'repo_abbrev', which is already checked against being non null at the
>> beginning of the function.
> [...]
>> -			if (repo_abbrev)
>> +			if (*repo_abbrev)
>>  				free(*repo_abbrev);
> 
> But now the test is useless, because free(NULL) is defined to be a
> no-op.
> 
Yes, indeed. Thanks for reviewing.

Stepping two steps back, I am trying to figure out, what this repo_abrev thing is doing, as I could find no documentation.

It's passed as a double pointer as declared in mailmap.h: int read_mailmap(struct string_list *map, char **repo_abbrev);

However grepping for "read_mailmap(" (bracket to prevent finding 
read_mailmap_XXX as often used in mailmap.c itself) 
	grep -nHIirF --exclude-dir=.git -- "read_mailmap("
throughout all the sources I just find one occurence having the
second argument not being 'NULL' and that is in 
	builtin/shortlog.c:212:	read_mailmap(&log->mailmap, &log->common_repo_prefix);
which turns out to be:
void shortlog_init(struct shortlog *log)
{
	memset(log, 0, sizeof(*log));
	read_mailmap(&log->mailmap, &log->common_repo_prefix);
	...

So we're passing there an address, which was just set to zero. This is the only occurence of passing a value at all and the value being passed is 0, so the free in the original patch doesn't need that check either.

As I am resending the patch, could somebody please explain me the mechanism of the "# repo-abbrev:" line? Even git itself doesn't use it in the .mailmap file, but a quick google search shows up only kernel repositories.

Stefan
Previous: Jeff KingNext: Stefan Beller
Message 4 of 12 in “mailmap: fix check for freeing memory”
  1. mailmap: fix check for freeing memoryStefan Beller, Aug 20, 2013
  2. Thomas RastAug 20, 2013
  3. Jeff KingAug 20, 2013
  4. Stefan BellerAug 20, 2013
  5. mailmap: remove redundant check for freeing memoryStefan Beller, Aug 20, 2013
  6. Jeff KingAug 20, 2013
  7. Thomas RastAug 20, 2013
  8. Stefan BellerAug 20, 2013
  9. Jeff KingAug 20, 2013
  10. Junio C HamanoAug 20, 2013
  11. Jeff KingAug 20, 2013
  12. Jeff KingAug 20, 2013

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.