From 582d209217facc18cdc3b179a9b4bbf22a94828d Mon Sep 17 00:00:00 2001 From: atmos4 Date: Sun, 24 Mar 2002 03:07:18 +0000 Subject: [PATCH] 10l fix memory allocation git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@5304 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_mov.c | 8 ++++++-- libmpdemux/parse_mp4.c | 15 +++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libmpdemux/demux_mov.c b/libmpdemux/demux_mov.c index d33547f4f5..9b3e3278fb 100644 --- a/libmpdemux/demux_mov.c +++ b/libmpdemux/demux_mov.c @@ -707,7 +707,7 @@ static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Found MPEG4 audio Elementary Stream Descriptor atom (%d)!\n", atom_len); if(atom_len >= 8) { esds_t *esds = (esds_t *)malloc(sizeof(esds_t)); - if(!mp4_parse_esds(&trak->stdata[36], atom_len-8, esds)) { + if(esds && !mp4_parse_esds(&trak->stdata[36], atom_len-8, esds)) { sh->i_bps = esds->avgBitrate/8; @@ -716,7 +716,11 @@ static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak sh->codecdata = (unsigned char *)malloc(sh->codecdata_len); memcpy(sh->codecdata, esds->decoderConfig, sh->codecdata_len); } - free(esds); + if(esds) { + if(esds->decoderConfig) + free(esds->decoderConfig); + free(esds); + } #if 0 { FILE* f=fopen("esds.dat","wb"); fwrite(&trak->stdata[36],atom_len-8,1,f); diff --git a/libmpdemux/parse_mp4.c b/libmpdemux/parse_mp4.c index e17703e6d5..512496984c 100644 --- a/libmpdemux/parse_mp4.c +++ b/libmpdemux/parse_mp4.c @@ -13,6 +13,7 @@ #include "stream.h" #define MP4_DL MSGL_V +#define freereturn(a,b) free(a); return b int mp4_read_descr_len(stream_t *s) { uint8_t b; @@ -45,7 +46,7 @@ int mp4_parse_esds(unsigned char *data, int datalen, esds_t *esds) { if (tag == MP4ESDescrTag) { /* read length */ if ((len = mp4_read_descr_len(s)) < 5 + 15) { - return 1; + freereturn(s,1); } esds->ESId = stream_read_word(s); esds->streamPriority = stream_read_char(s); @@ -65,12 +66,12 @@ int mp4_parse_esds(unsigned char *data, int datalen, esds_t *esds) { /* get and verify DecoderConfigDescrTab */ if (stream_read_char(s) != MP4DecConfigDescrTag) { - return 1; + freereturn(s,1); } /* read length */ if ((len = mp4_read_descr_len(s)) < 15) { - return 1; + freereturn(s,1); } esds->objectTypeId = stream_read_char(s); @@ -91,13 +92,12 @@ int mp4_parse_esds(unsigned char *data, int datalen, esds_t *esds) { /* get and verify DecSpecificInfoTag */ if (stream_read_char(s) != MP4DecSpecificDescrTag) { - return 1; + freereturn(s,1); } /* read length */ esds->decoderConfigLen = len = mp4_read_descr_len(s); - free(esds->decoderConfig); esds->decoderConfig = malloc(esds->decoderConfigLen); if (esds->decoderConfig) { stream_read(s, esds->decoderConfig, esds->decoderConfigLen); @@ -108,7 +108,10 @@ int mp4_parse_esds(unsigned char *data, int datalen, esds_t *esds) { "ESDS MPEG4 Decoder Specific Descriptor (%dBytes)\n", len); /* will skip the remainder of the atom */ - return 0; + freereturn(s,0); } +#undef freereturn +#undef MP4_DL +