CVS change done by Reimar Döffinger CVS Update of /cvsroot/mplayer/main/Gui In directory mail:/var2/tmp/cvs-serv8765 Modified Files: interface.c Log Message: Yet another memleak... Index: interface.c =================================================================== RCS file: /cvsroot/mplayer/main/Gui/interface.c,v retrieving revision 1.102 retrieving revision 1.103 diff -u -r1.102 -r1.103 --- interface.c 6 Jan 2005 18:10:36 -0000 1.102 +++ interface.c 31 Jan 2005 18:16:39 -0000 1.103 @@ -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); } #endif #if defined(HAVE_ALSA9) || defined (HAVE_ALSA1X) @@ -856,8 +857,9 @@ tmp = calloc( 1,strlen( gtkAOALSADevice ) + 14 ); sprintf( tmp,"alsa:device=%s",gtkAOALSADevice ); } else - tmp = "alsa"; + tmp = strdup("alsa"); gaddlist( &audio_driver_list,tmp ); + free(tmp); } #endif #ifdef HAVE_SDL @@ -868,8 +870,9 @@ tmp = calloc( 1,strlen( gtkAOSDLDriver ) + 10 ); sprintf( tmp,"sdl:%s",gtkAOSDLDriver ); } else - tmp = "sdl"; + tmp = strdup("sdl"); gaddlist( &audio_driver_list,tmp ); + free(tmp); } #endif // -- subtitle
Hi, Le lundi 31 janvier 2005 à 19:16 +0100, Reimar D?finger CVS a écrit :
CVS change done by Reimar Döffinger CVS
Update of /cvsroot/mplayer/main/Gui In directory mail:/var2/tmp/cvs-serv8765
Modified Files: interface.c Log Message: Yet another memleak...
Index: interface.c =================================================================== RCS file: /cvsroot/mplayer/main/Gui/interface.c,v retrieving revision 1.102 retrieving revision 1.103 diff -u -r1.102 -r1.103 --- interface.c 6 Jan 2005 18:10:36 -0000 1.102 +++ interface.c 31 Jan 2005 18:16:39 -0000 1.103 @@ -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? 'cause when I run: find -name "*.c" -type f -exec grep -q "= \"" {} \; -print I catch lots of those, just like in libavformat/audio.c, line 52: if (!audio_device) audio_device = "/dev/dsp"; So there, it should read if (!audio_device) audio_device = strdup("/dev/dsp"); and later free(audio_device) or is that just okay here as audio_device is provided by the caller, which should take care of that? ... just trying to help... I'm quite confident that that lots of those are perfectly legal, or you'd have fixed them already... ;-) Regards, Guillaume
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
participants (3)
-
Guillaume POIRIER -
Reimar Döffinger -
syncmail@mplayerhq.hu