[MPlayer-dev-eng] [PATCH][BUG] Incorrect memleak fix code in input/input.c might cause incorrect free

Alexander Strasser eclipse7 at gmx.net
Tue Aug 3 10:24:51 CEST 2004


On Tue, Aug 03, 2004 at 12:35:56AM +0200, Alexander Strasser wrote:
> On Mon, Aug 02, 2004 at 06:43:33PM +0200, Alexander Strasser wrote:
> > On Mon, Aug 02, 2004 at 07:24:21PM +0300, Shachar Raindel wrote:
> > > The patch this time is much more clean. I think I found the most
> > > elegant solution - free file only if it is not the same as
> > > config_file, and remove the weird stuff in the if added by alex. This
> > > should do the trick, without any unneeded memory allocations (and BTW,
> > > I was wrong about the ternary operator - only one of the expressions
> > > is evaluate, so when one writes "a?b:c" than a is evaluated, and
> > > afterward either b or c, but not both).
> > Seems like a good and correct solution to me.
> > I will commit it tonight if nobody objects.
> Strangely your patch didn't apply, though that's no big problem for
> this tiny patch...
> But i got some doubts as i looked at the situation again.
> So this is delayed until tommorow.
OK, i knew i had some doubts and now i found why.
Please look at the attached patch and comment.

  Alex (beastd)
-------------- next part --------------
Index: input/input.c
===================================================================
RCS file: /cvsroot/mplayer/main/input/input.c,v
retrieving revision 1.91
diff -u -u -r1.91 input.c
--- input/input.c	23 Jul 2004 16:10:21 -0000	1.91
+++ input/input.c	3 Aug 2004 08:21:29 -0000
@@ -1484,15 +1484,24 @@
   if(!file)
     return;
   
-  if( mp_input_parse_config(file)) {
-    free(file); // release the buffer created by get_path()
-  }
-  else {
+  if( !mp_input_parse_config(file)) {
+    // free file if it was allocated by get_path(),
+    // before it gets overwritten
+    if( file != config_file)
+    {
+      free(file);
+    }
     // Try global conf dir
     file = MPLAYER_CONFDIR "/input.conf";
     if(! mp_input_parse_config(file))
       mp_msg(MSGT_INPUT,MSGL_WARN,"Falling back on default (hardcoded) input config\n");
   }
+  else
+  {
+    // free file if it was allocated by get_path()
+    if( file != config_file)
+      free(file);
+  }
 
 #ifdef HAVE_JOYSTICK
   if(use_joystick) {


More information about the MPlayer-dev-eng mailing list