diff options
author | Przemysław Sobala <przemyslaw.sobala@grupawp.pl> | 2015-09-29 15:25:07 +0200 |
---|---|---|
committer | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2015-10-09 21:56:15 +0200 |
commit | eb681e1fac2cdbdf81d535217934144ead347166 (patch) | |
tree | e0dd59643d181b1e1deb3944e0b19da01d00b2bc | |
parent | 9177bcc06ca5fa583608b5a6d77c6d2bebe9def6 (diff) | |
download | ffmpeg-eb681e1fac2cdbdf81d535217934144ead347166.tar.gz |
lavf/img2dec: Fix memory leak
Fixes #4886
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 01dd7e025c246d9001f1a30f4a5d8fa2936d1a5e)
-rw-r--r-- | libavformat/img2dec.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index 1a31ac870b..78e2102308 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -440,14 +440,17 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) } res = av_new_packet(pkt, size[0] + size[1] + size[2]); - if (res < 0) - return res; + if (res < 0) { + goto fail; + } pkt->stream_index = 0; pkt->flags |= AV_PKT_FLAG_KEY; if (s->ts_from_file) { struct stat img_stat; - if (stat(filename, &img_stat)) - return AVERROR(EIO); + if (stat(filename, &img_stat)) { + res = AVERROR(EIO); + goto fail; + } pkt->pts = (int64_t)img_stat.st_mtime; #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC if (s->ts_from_file == 2) @@ -481,18 +484,29 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) { av_free_packet(pkt); if (ret[0] < 0) { - return ret[0]; + res = ret[0]; } else if (ret[1] < 0) { - return ret[1]; - } else if (ret[2] < 0) - return ret[2]; - return AVERROR_EOF; + res = ret[1]; + } else if (ret[2] < 0) { + res = ret[2]; + } else { + res = AVERROR_EOF; + } + goto fail; } else { s->img_count++; s->img_number++; s->pts++; return 0; } + +fail: + if (!s->is_pipe) { + for (i = 0; i < 3; i++) { + avio_closep(&f[i]); + } + } + return res; } static int img_read_close(struct AVFormatContext* s1) |