Thread (1 message) 1 message, 1 author, 2020-01-06

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

From: Andreas Schwab <hidden>
Date: 2020-01-06 23:34:57

On Jan 06 2020, Jeff King wrote:
On Mon, Jan 06, 2020 at 10:15:53PM +0100, Miriam R. wrote:
quoted
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."
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help