[libdvdnav-devel] [RFC] Set free'd variables to NULL or not?
Jean-Baptiste Kempf
jb at videolan.org
Fri Oct 24 17:48:19 CEST 2014
Le 24/10/2014 17:45, Andrew Clayton a écrit :
> On Fri, 24 Oct 2014 16:26:56 +0200, Jean-Baptiste Kempf wrote:
>
>> On 24 Oct, Andrew Clayton wrote :
>>> I notice it is common practice in libdvdread to set free'd variables
>>> to NULL. There are of course arguments for and against.
>>
>> What is the use of setting them to NULL?
>> Are they going to be reused and checked?
>
> I personally don't set them to NULL in my projects. Some people do and
> that seems to be the case in libdvdread. If anything it can probably
> hide bugs, for example where you might be doing a double free.
>
> If the consensus is to not set things to NULL after free then they can
> simply be removed.
Setting to NULL a variable, after free, is, in the general case, wrong
and stupid, and error-prone.
However, be careful that, in libdvdread, the variable life-cycle is a
bit weird, because of struct re-use and therefore, it avoids crashes.
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
More information about the libdvdnav-devel
mailing list