[asterisk-dev] [Code Review]: automagically set a pointer to null after it is freed with ast_free

Kevin P. Fleming kpfleming at digium.com
Tue Sep 20 09:47:17 CDT 2011


On 09/20/2011 08:00 AM, Benny Amorsen wrote:
> "Kevin P. Fleming"<kpfleming at digium.com>  writes:
>
>> We have had similar discussions about pointers to astobj2 reference
>> counted objects; it has been my opinion since we introduced astobj2
>> that releasing a reference to an object should clear the pointer that
>> held the reference (although the code still does not actually do
>> this).
>
> If you use a value in the zero page which isn't actually NULL (e.g. 1 or
> 4095), you catch both double-free and use-after-free.
>
> The downside is that you lose the value of the pointer which can be
> inconvenient for valgrind. The same applies to using NULL of course.

I think we've all pretty much agreed that we aren't going to do this 
stuff anyway (although as an optional behavior it might be useful, since 
it would not slow down Asterisk as much as running under Valgrind does). 
In spite of that... this sort of thing is quite easy, just declare a 
'static const int dont_touch_me = 1;' in some file in the main Asterisk 
binary, and use its address as the 'flag' value for freed pointers.

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
Jabber: kfleming at digium.com | SIP: kpfleming at digium.com | Skype: kpfleming
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at www.digium.com & www.asterisk.org



More information about the asterisk-dev mailing list