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