[PATCH] leak fixes for loop mode
Dear all, 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. The leaks were detected using valgrind. Regards, Timothy Lee diff -Naur -wbBE main-cvs/libmpdemux/demuxer.c main-leakfix/libmpdemux/demuxer.c --- main-cvs/libmpdemux/demuxer.c 2005-01-20 08:50:12.000000000 +0800 +++ main-leakfix/libmpdemux/demuxer.c 2005-02-04 17:31:26.000000000 +0800 @@ -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: @@ -1059,6 +1059,7 @@ } //=============== Try to open as MPEG-ES file: ================= if(file_format==DEMUXER_TYPE_MPEG_ES || file_format==DEMUXER_TYPE_MPEG4_ES || file_format==DEMUXER_TYPE_H264_ES){ // little hack, see above! + if (demuxer) free_demuxer(demuxer); demuxer=new_demuxer(stream,file_format,audio_id,video_id,dvdsub_id); if(!ds_fill_buffer(demuxer->video)){ mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_InvalidMPEGES); diff -Naur -wbBE main-cvs/libmpdemux/demux_ogg.c main-leakfix/libmpdemux/demux_ogg.c --- main-cvs/libmpdemux/demux_ogg.c 2005-01-24 11:30:58.000000000 +0800 +++ main-leakfix/libmpdemux/demux_ogg.c 2005-02-04 17:31:26.000000000 +0800 @@ -764,6 +764,7 @@ /// Error if(np < 0) { mp_msg(MSGT_DEMUX,MSGL_DBG2,"Ogg demuxer : Bad page sync\n"); + ogg_sync_clear(sync); free(ogg_d); return 0; } @@ -773,6 +774,7 @@ buf = ogg_sync_buffer(sync,BLOCK_SIZE); len = stream_read(s,buf,BLOCK_SIZE); if(len == 0 && s->eof) { + ogg_sync_clear(sync); free(ogg_d); return 0; } @@ -1057,6 +1059,7 @@ } if(!n_video && !n_audio) { + ogg_sync_clear(sync); free(ogg_d); return 0; } diff -Naur -wbBE main-cvs/mplayer.c main-leakfix/mplayer.c --- main-cvs/mplayer.c 2005-01-24 11:30:56.000000000 +0800 +++ main-leakfix/mplayer.c 2005-02-04 17:31:26.000000000 +0800 @@ -501,7 +501,13 @@ current_module="exit_player"; // free mplayer config - free(mconfig); + m_config_free(mconfig); + + // free playtree + play_tree_free(playtree, 1); + + // free OSD + free_osd_list(); #ifdef USE_EDL if(edl_records != NULL) free(edl_records); // free mem allocated for EDL diff -Naur -wbBE main-cvs/osdep/getch2.c main-leakfix/osdep/getch2.c --- main-cvs/osdep/getch2.c 2004-04-06 05:33:08.000000000 +0800 +++ main-leakfix/osdep/getch2.c 2005-02-04 17:31:26.000000000 +0800 @@ -73,6 +73,7 @@ getch2_keys[getch2_key_db].code=code; ++getch2_key_db; /* printf("%s=%s\n",id,p); */ + if (p != term_p) free(p); } static int success=0;
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
Hi, On Sat, Feb 05, 2005 at 11:57:46AM +0100, Reimar Döffinger wrote:
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).
Won't have time to have a closer look at these.
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.
Applied this. Greetings, Reimar Döffinger
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.
diff -Naur -wbBE main-cvs/osdep/getch2.c main-leakfix/osdep/getch2.c --- main-cvs/osdep/getch2.c 2004-04-06 05:33:08.000000000 +0800 +++ main-leakfix/osdep/getch2.c 2005-02-04 17:31:26.000000000 +0800 @@ -73,6 +73,7 @@ getch2_keys[getch2_key_db].code=code; ++getch2_key_db; /* printf("%s=%s\n",id,p); */ + if (p != term_p) free(p); }
static int success=0;
Is this hunk still relevant? The rest of the patch was applied. Diego
participants (3)
-
Diego Biurrun -
Reimar Döffinger -
Timothy Lee