diff options
author | Dale Curtis <dalecurtis@chromium.org> | 2012-04-12 17:50:55 -0700 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-04-13 11:59:27 +0200 |
commit | a6b3e6d0b49b47c9b874e59b88a8051af338f520 (patch) | |
tree | 5050a7df7e0cef1f646d5586a6599bc4d23d53b4 | |
parent | ab3fcd93fde5f876e5e6879a2b78e8cbcde98ab5 (diff) | |
download | ffmpeg-a6b3e6d0b49b47c9b874e59b88a8051af338f520.tar.gz |
mov: Fix memory leaks on aborted header parsing.
If mov_read_header exits under error, the memory allocated is
not freed.
Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/mov.c | 74 |
1 files changed, 41 insertions, 33 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c index d3bd2280a2..5b81ba8723 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2765,6 +2765,45 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) return 0; } +static int mov_read_close(AVFormatContext *s) +{ + MOVContext *mov = s->priv_data; + int i, j; + + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + MOVStreamContext *sc = st->priv_data; + + av_freep(&sc->ctts_data); + for (j = 0; j < sc->drefs_count; j++) { + av_freep(&sc->drefs[j].path); + av_freep(&sc->drefs[j].dir); + } + av_freep(&sc->drefs); + if (sc->pb && sc->pb != s->pb) + avio_close(sc->pb); + av_freep(&sc->chunk_offsets); + av_freep(&sc->keyframes); + av_freep(&sc->sample_sizes); + av_freep(&sc->stps_data); + av_freep(&sc->stsc_data); + av_freep(&sc->stts_data); + } + + if (mov->dv_demux) { + for (i = 0; i < mov->dv_fctx->nb_streams; i++) { + av_freep(&mov->dv_fctx->streams[i]->codec); + av_freep(&mov->dv_fctx->streams[i]); + } + av_freep(&mov->dv_fctx); + av_freep(&mov->dv_demux); + } + + av_freep(&mov->trex_data); + + return 0; +} + static int mov_read_header(AVFormatContext *s) { MOVContext *mov = s->priv_data; @@ -2782,10 +2821,12 @@ static int mov_read_header(AVFormatContext *s) /* check MOV header */ if ((err = mov_read_default(mov, pb, atom)) < 0) { av_log(s, AV_LOG_ERROR, "error reading header: %d\n", err); + mov_read_close(s); return err; } if (!mov->found_moov) { av_log(s, AV_LOG_ERROR, "moov atom not found\n"); + mov_read_close(s); return AVERROR_INVALIDDATA; } av_dlog(mov->fc, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb)); @@ -2985,39 +3026,6 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti return 0; } -static int mov_read_close(AVFormatContext *s) -{ - MOVContext *mov = s->priv_data; - int i, j; - - for (i = 0; i < s->nb_streams; i++) { - AVStream *st = s->streams[i]; - MOVStreamContext *sc = st->priv_data; - - av_freep(&sc->ctts_data); - for (j = 0; j < sc->drefs_count; j++) { - av_freep(&sc->drefs[j].path); - av_freep(&sc->drefs[j].dir); - } - av_freep(&sc->drefs); - if (sc->pb && sc->pb != s->pb) - avio_close(sc->pb); - } - - if (mov->dv_demux) { - for (i = 0; i < mov->dv_fctx->nb_streams; i++) { - av_freep(&mov->dv_fctx->streams[i]->codec); - av_freep(&mov->dv_fctx->streams[i]); - } - av_freep(&mov->dv_fctx); - av_freep(&mov->dv_demux); - } - - av_freep(&mov->trex_data); - - return 0; -} - static const AVOption options[] = { {"use_absolute_path", "allow using absolute path when opening alias, this is a possible security issue", |