[MPlayer-dev-eng] [PATCH] leak fixes for loop mode

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Feb 5 11:57:46 CET 2005


Hi,
On Sat, Feb 05, 2005 at 02:26:57PM +0800, Timothy Lee wrote:
> This patch fixes leaks which are noticeable when MPlayer runs in loop 
> mode.  The failure to clean up the data buffer used by Tremor after file 
> detection loses 6.4 kbyte for every loop.

Thanks for the work, though the last parts seem not important to me, as
it should not cause a leak but only memory that isn't free directly
before exit, which does not really matter IMHO (though it is not good
style).
I had a closer look at the first two, and modified them, see attached. I
did not yet test, so if you can please do so.

Greetings,
Reimar Döffinger
-------------- next part --------------
? cvs-diff
? mplconf
Index: libmpdemux/demux_ogg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_ogg.c,v
retrieving revision 1.65
diff -u -r1.65 demux_ogg.c
--- libmpdemux/demux_ogg.c	22 Jan 2005 14:28:23 -0000	1.65
+++ libmpdemux/demux_ogg.c	5 Feb 2005 10:56:50 -0000
@@ -731,6 +731,8 @@
   return (index < 0) ? NULL : (index >= ogg_d->n_text) ? NULL : ogg_d->text_langs[index];
 }
 
+void demux_close_ogg(demuxer_t* demuxer);
+
 /// Open an ogg physical stream
 int demux_ogg_open(demuxer_t* demuxer) {
   ogg_demuxer_t* ogg_d;
@@ -764,8 +766,7 @@
     /// Error
     if(np < 0) {
       mp_msg(MSGT_DEMUX,MSGL_DBG2,"Ogg demuxer : Bad page sync\n");
-      free(ogg_d);
-      return 0;
+      goto err_out;
     }
     /// Need some more data
     if(np == 0) {
@@ -773,8 +774,7 @@
       buf = ogg_sync_buffer(sync,BLOCK_SIZE);
       len = stream_read(s,buf,BLOCK_SIZE);      
       if(len == 0 && s->eof) {
-	free(ogg_d);
-	return 0;
+	goto err_out;
       }
       ogg_sync_wrote(sync,len);
       continue;
@@ -1057,8 +1057,7 @@
   }
 
   if(!n_video && !n_audio) {
-    free(ogg_d);
-    return 0;
+    goto err_out;
   }
 
   /// Finish to setup the demuxer
@@ -1095,6 +1094,10 @@
   mp_msg(MSGT_DEMUX,MSGL_V,"Ogg demuxer : found %d audio stream%s, %d video stream%s and %d text stream%s\n",n_audio,n_audio>1?"s":"",n_video,n_video>1?"s":"",ogg_d->n_text,ogg_d->n_text>1?"s":"");
  
   return 1;
+
+err_out:
+  demux_close_ogg(demuxer);
+  return 0;
 }
 
 
Index: libmpdemux/demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.181
diff -u -r1.181 demuxer.c
--- libmpdemux/demuxer.c	15 Jan 2005 16:11:45 -0000	1.181
+++ libmpdemux/demuxer.c	5 Feb 2005 10:56:55 -0000
@@ -219,13 +219,13 @@
       demux_close_rtp(demuxer); break;
 #endif
     case DEMUXER_TYPE_SMJPEG:
-      demux_close_smjpeg(demuxer); return;
+      demux_close_smjpeg(demuxer); break;
     case DEMUXER_TYPE_DEMUXERS:
-      demux_close_demuxers(demuxer); return;
+      demux_close_demuxers(demuxer); break;
     case DEMUXER_TYPE_AVI: 
     case DEMUXER_TYPE_AVI_NI:
     case DEMUXER_TYPE_AVI_NINI:
-      demux_close_avi(demuxer); return;
+      demux_close_avi(demuxer); break;
 #ifdef HAVE_XMMS
     case DEMUXER_TYPE_XMMS:
       demux_close_xmms(demuxer); break;
@@ -250,10 +250,10 @@
 #endif
     }
     // free streams:
-    for(i=0;i<256;i++){
+    for(i = 0; i < MAX_A_STREAMS; i++)
 	if(demuxer->a_streams[i]) free_sh_audio(demuxer->a_streams[i]);
+    for(i = 0; i < MAX_V_STREAMS; i++)
 	if(demuxer->v_streams[i]) free_sh_video(demuxer->v_streams[i]);
-    }
     //if(sh_audio) free_sh_audio(sh_audio);
     //if(sh_video) free_sh_video(sh_video);
     // free demuxers:
@@ -1050,6 +1050,8 @@
         mp_msg(MSGT_DEMUXER,MSGL_ERR,"MPEG: " MSGTR_MissingVideoStreamBug);
       else
         mp_msg(MSGT_DEMUXER,MSGL_V,MSGTR_NotSystemStream);
+    }
+    if (demuxer && file_format != DEMUXER_TYPE_MPEG_PS) {
       free_demuxer(demuxer);
       demuxer = NULL;
     }


More information about the MPlayer-dev-eng mailing list