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

Re: [Outreachy] Return value before or after free()?

From
Andreas Schwab <schwab@linux-m68k.org>
Date
Jan 6, 2020, 23:34 UTC
Message-ID
<87imlo6twj.fsf@igel.home>
In-Reply-To
<20200106213051.GD980197@coredump.intra.peff.net>
On Jan 06 2020, Jeff King wrote:
Show 16 quoted lines
> On Mon, Jan 06, 2020 at 10:15:53PM +0100, Miriam R. wrote:
>
>> in run-command.c file `exists_in_PATH()` function does this:
>> 
>> static int exists_in_PATH(const char *file)
>> {
>> char *r = locate_in_PATH(file);
>> free(r);
>> return r != NULL;
>> }
>> 
>> I wonder if it is correct to do return r != NULL; after free(r);
>
> It is technically undefined behavior according to the C standard, but I
> think it would be hard to find an implementation where it was not
> perfectly fine in practice.

Compilers get constantly better at exploiting undefined behaviour, so I would not count on it.

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Previous: Jonathan NiederNext: brian m. carlson
Message 4 of 7 in “[Outreachy] Return value before or after free()?”
  1. Miriam R.Jan 6, 2020
  2. Jeff KingJan 6, 2020
  3. Jonathan NiederJan 6, 2020
  4. Andreas SchwabJan 6, 2020
  5. brian m. carlsonJan 7, 2020
  6. brian m. carlsonJan 7, 2020
  7. Miriam R.Jan 7, 2020

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.