[asterisk-dev] [Code Review]: automagically set a pointer to null after it is freed with ast_free
Simon Perreault
simon.perreault at viagenie.ca
Fri Sep 16 09:55:51 CDT 2011
David Vossel wrote, on 09/16/2011 10:47 AM:
> I don't think we can change the behavior of ast_free(), but this functionality seems useful. I write the following lines all the time.
>
> ast_free(blah);
> blah = NULL;
Well, you should stop doing that, for the reasons previously stated.
Here's a "prisoner's dilemma-style" matrix to illustrate:
| Set to null | Do not set to null
--------------------+-----------------+------------------------------------
Double free | Undetectable | Detectable with Valgrind or similar
Use of freed memory | Immediate crash | Detectable with Valgrind or similar
As you can see, the "do not set to null" option is better overall.
Simon
--
DTN made easy, lean, and smart --> http://postellation.viagenie.ca
NAT64/DNS64 open-source --> http://ecdysis.viagenie.ca
STUN/TURN server --> http://numb.viagenie.ca
More information about the asterisk-dev
mailing list