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

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

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jan 7, 2020, 01:58 UTC
Message-ID
<20200107015859.GJ6570@camp.crustytoothpaste.net>
In-Reply-To
<20200107010809.GH6570@camp.crustytoothpaste.net>
On 2020-01-07 at 01:08:09, brian m. carlson wrote:
Show 14 quoted lines
> Unfortunately, compilers have gotten much more aggressive about assuming
> that undefined behavior never occurs and rewriting code based on that.
> clang is not as bad about doing that, but GCC is very aggressive about
> it.  There are multiple instances where NULL pointer checks have been
> optimized out because the compiler exploited undefined behavior to
> assume a pointer was never NULL.
> 
> In this case, the only case in which we can safely assume that this
> behavior is acceptable is that r is NULL, in which case C11 tells us
> that "no action occurs" due to the free. So the compiler could just
> optimize this out to a "return 0".  Just because it doesn't now doesn't
> mean we can assume it won't in the future, so we do need to fix this.
> 
> I'll send a patch.

Oof, I just realized that you had tagged this with "[Outreachy]", which means that you were probably planning on sending a patch to fix this, and then I went and did it instead, so let me apologize for doing that.

I sent it because oftentimes we say "we should fix this thing" and then never do it because nobody sends a patch, but in this case I should have paid more attention and waited for you to respond and send one instead.

Again, sorry about that.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: brian m. carlsonNext: Miriam R.
Message 6 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.