From 02f5ebf1d5fc226f7fa2ee2ea1f29d42c44e21a6 Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 6 Feb 2005 10:30:10 +0000 Subject: [PATCH] Memleak fixes. Based on patch by Timothy Lee (timothy lee at siriushk com). git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@14667 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_ogg.c | 15 +++++++++------ libmpdemux/demuxer.c | 12 +++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libmpdemux/demux_ogg.c b/libmpdemux/demux_ogg.c index ddb4adb7b6..6d3142aa73 100644 --- a/libmpdemux/demux_ogg.c +++ b/libmpdemux/demux_ogg.c @@ -731,6 +731,8 @@ char *demux_ogg_sub_lang(demuxer_t *demuxer, int index) { 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 @@ int demux_ogg_open(demuxer_t* demuxer) { /// 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 @@ int demux_ogg_open(demuxer_t* demuxer) { 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 @@ int demux_ogg_open(demuxer_t* demuxer) { } if(!n_video && !n_audio) { - free(ogg_d); - return 0; + goto err_out; } /// Finish to setup the demuxer @@ -1095,6 +1094,10 @@ int demux_ogg_open(demuxer_t* demuxer) { 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; } diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c index d6f91e0ce7..cf009d95c3 100644 --- a/libmpdemux/demuxer.c +++ b/libmpdemux/demuxer.c @@ -219,13 +219,13 @@ void free_demuxer(demuxer_t *demuxer){ 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 @@ void free_demuxer(demuxer_t *demuxer){ #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 @@ if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_MPEG_PS){ 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; }