[asterisk-dev] [Code Review] automagically set a pointer to null after it is freed with ast_free
Benny Amorsen
benny+usenet at amorsen.dk
Fri Sep 16 08:37:28 CDT 2011
tony at softins.co.uk (Tony Mountifield) writes:
> In article <20110916000323.17691.46179 at hotblack.digium.com>,
> Simon Perreault <reviewboard at asterisk.org> wrote:
>>
>> I have a major problem with this. It hides bugs rather than fixing them. Double frees and
>> other such problems are coding errors that are not simply fixed by setting the pointer to
>> zero. If you double free a pointer, odds are there are deeper issues in your code that need
>> to be fixed. Crashing is a good indicator that there is something that needs to be fixed. If
>> you set the pointer to zero, you trade an often immediate crash for a later crash.
>
> It could be the other way round: continuing to dereference a pointer after
> its referent has been freed may well continue to work for a while, and if
> the referred-to area gets reused, behaviour can be undefined and appear
> quite unrelated to the root cause of the error. If the pointer is set to
> NULL when freed, any attempt to dereference it will immediately crash,
> making the problem much easier to diagnose.
Combine the advantages: Set the pointer to something which is not NULL
but guaranteed to crash. 1 might work?
/Benny
More information about the asterisk-dev
mailing list