History

zerocodec: Fix memleak in decode_frame

If there was a failure inflating, or reinitializing the zstream, the current frame's buffer would be lost.

Derek Buitenhuis committed 14 years ago

Commit fcf550c1 parent d6124d01 file · +6 −5Browse files

Unified · Split

libavcodec/zerocodec.c+6−5
@@ -51,17 +51,17 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, · 50 unmodified lines
5151 pic->pict_type = AV_PICTURE_TYPE_P;
5252 }
5353
54− if (avctx->get_buffer(avctx, pic) < 0) {
55− av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
56− return AVERROR(ENOMEM);
57− }
58−
5954 zret = inflateReset(zstream);
6055 if (zret != Z_OK) {
6156 av_log(avctx, AV_LOG_ERROR, "Could not reset inflate: %d.\n", zret);
6257 return AVERROR_INVALIDDATA;
6358 }
6459
60+ if (avctx->get_buffer(avctx, pic) < 0) {
61+ av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
62+ return AVERROR(ENOMEM);
63+ }
64+
6565 zstream->next_in = avpkt->data;
6666 zstream->avail_in = avpkt->size;
6767
@@ -78,6 +78,7 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, · 10 unmodified lines
7878
7979 zret = inflate(zstream, Z_SYNC_FLUSH);
8080 if (zret != Z_OK && zret != Z_STREAM_END) {
81+ avctx->release_buffer(avctx, pic);
8182 av_log(avctx, AV_LOG_ERROR,
8283 "Inflate failed with return code: %d.\n", zret);
8384 return AVERROR_INVALIDDATA;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t