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

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

From
Jeff King <peff@peff.net>
Date
Aug 20, 2013, 13:52 UTC
Message-ID
<20130820135230.GA32370@sigill.intra.peff.net>
In-Reply-To
<878uzw7a6l.fsf@linux-k42r.v.cablecom.net>
On Tue, Aug 20, 2013 at 03:40:02PM +0200, Thomas Rast wrote:
Show 13 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.
Yeah, I think we should just drop the conditional completely.

I am not sure of the complete back-story. The earlier check for repo_abbrev to be non-NULL was added by 8503ee4, after this check on free() already existed. So that was when this conditional became redundant.

But the line right after this one unconditionally assigns to "*repo_abbrev", so we would always segfault in such a case anyway (which is what 8503ee4 was fixing).

So I think it was either a misguided "don't pass NULL to free" check that was simply wrong, or it was an incomplete "make sure repo_abbrev is not NULL" check. And the first is useless, and the second is now redundant due to 8503ee4. So it should simply be free().

-Peff
Previous: Thomas RastNext: Stefan Beller
Message 3 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.