[libdvdnav-devel] [RFC] Set free'd variables to NULL or not?

Andrew Clayton andrew at digital-domain.net
Sat Oct 25 02:26:55 CEST 2014


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?

Getting back to my original query...

In src/dvd_reader.c there is a function

 937 void DVDCloseFile( dvd_file_t *dvd_file )
 938 {
 939   if( dvd_file && dvd_file->dvd ) {
 940     if( !dvd_file->dvd->isImageFile ) {
 941       int i;
 942 
 943       for( i = 0; i < TITLES_MAX; ++i ) {
 944         if( dvd_file->title_devs[ i ] ) {
 945           dvdinput_close( dvd_file->title_devs[i] );
 946         }
 947       }
 948     }
 949 
 950     free( dvd_file );
 951     dvd_file = NULL;
 952   }
 953 }

In that function the variable dvd_file might be free'd
and then set to NULL. As it stands setting it to NULL
has no real effect (dvd_file is passed in by value).

So my question is should we just remove the setting of it to NULL, it
clearly works with this in effect now . Or should the NULLing be
propagated back to the calling function?

Given the way it is now and having looked at the code, I think the
setting of it to NULL can just be removed.

Cheers,
Andrew


More information about the libdvdnav-devel mailing list