[MPlayer-cvslog] CVS: main/libmpdemux muxer.c,1.14,1.15
Michael Niedermayer
michaelni at gmx.at
Sun Mar 12 21:58:27 CET 2006
Hi
On Sun, Mar 12, 2006 at 07:13:14PM +0100, Nico Sabbi CVS wrote:
> CVS change done by Nico Sabbi CVS
>
> Update of /cvsroot/mplayer/main/libmpdemux
> In directory mail:/var2/tmp/cvs-serv10439
>
> Modified Files:
> muxer.c
> Log Message:
> exit if calloc() fails; free(muxer) before returning NULL if muxer_init() fails (to avoid memleak). Fixes cid 173
>
> Index: muxer.c
> ===================================================================
> RCS file: /cvsroot/mplayer/main/libmpdemux/muxer.c,v
> retrieving revision 1.14
> retrieving revision 1.15
> diff -u -r1.14 -r1.15
> --- muxer.c 26 Jan 2006 19:32:07 -0000 1.14
> +++ muxer.c 12 Mar 2006 18:13:11 -0000 1.15
> @@ -21,30 +21,47 @@
> muxer_t *muxer_new_muxer(int type,FILE *f){
> muxer_t* muxer=malloc(sizeof(muxer_t));
> memset(muxer,0,sizeof(muxer_t));
> + if(!muxer)
> + return NULL;
memset before the check?!
> muxer->file = f;
> switch (type) {
> case MUXER_TYPE_MPEG:
> if(! muxer_init_muxer_mpeg(muxer))
> - return NULL;
> + {
> + free(muxer);
> + return NULL;
> + }
> break;
> case MUXER_TYPE_RAWVIDEO:
> if(! muxer_init_muxer_rawvideo(muxer))
> + {
> + free(muxer);
> return NULL;
> + }
> break;
> case MUXER_TYPE_RAWAUDIO:
> if(! muxer_init_muxer_rawaudio(muxer))
> + {
> + free(muxer);
> return NULL;
> + }
> break;
> #if defined(USE_LIBAVFORMAT) || defined(USE_LIBAVFORMAT_SO)
> case MUXER_TYPE_LAVF:
> if(! muxer_init_muxer_lavf(muxer))
> - return NULL;
> + {
> + free(muxer);
> + return NULL;
> + }
> break;
> #endif
> case MUXER_TYPE_AVI:
> default:
> if(! muxer_init_muxer_avi(muxer))
> - return NULL;
> + {
> + free(muxer);
> + return NULL;
> + }
> }
> return muxer;
> }
a goto fail; everywhere and a fail: if(muxer) free(muxer); return NULL; at
the end would be IMHO simpler and cleaner
[...]
--
Michael
More information about the MPlayer-cvslog
mailing list