[MPlayer-cvslog] CVS: main/Gui interface.c,1.102,1.103

Reimar Döffinger uvhe at rz.uni-karlsruhe.de
Mon Jan 31 21:27:44 CET 2005


Hi,
On Mon, Jan 31, 2005 at 08:47:16PM +0100, Guillaume POIRIER wrote:
> Le lundi 31 janvier 2005 à 19:16 +0100, Reimar D?finger CVS a écrit : 
> > @@ -842,8 +842,9 @@
> >  	  tmp = calloc( 1,strlen( gtkAOOSSDevice ) + 7 );
> >  	  sprintf( tmp,"oss:%s",gtkAOOSSDevice );
> >  	  } else
> > -	    tmp = "oss";
> > +	    tmp = strdup("oss");
> >  	  gaddlist( &audio_driver_list,tmp );
> > +	  free(tmp);
> >  	 }
> 
> Is that really only what it takes to have a memleak?

No, the memleak is because of that calloc at the top, where memory is
allocated. Normally just adding free(tmp) would be okay, but the
tmp="oss" makes tmp point to static memory (we didn't use an allocation
function to get it), on which I may not use free. Strdup copies the
static string into memory that was malloced.
Alternatively I could use a "must_free" variable and set it when I do
malloc and then call free only when this variable is set.
In other words am memleak is when there isn't a corresponding free for a
malloc somewhere - but mallocs can be hidden e.g. behind another
function like strdup.

Greetings,
Reimar Döffinger




More information about the MPlayer-cvslog mailing list