Commit 27801500 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '3919a457'

* commit '3919a457':
  jpeglsenc: Check memory allocations

Conflicts:
	libavcodec/jpeglsenc.c

See: 48214956Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 77010a41 3919a457
...@@ -255,7 +255,9 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, ...@@ -255,7 +255,9 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
PutBitContext pb, pb2; PutBitContext pb, pb2;
GetBitContext gb; GetBitContext gb;
uint8_t *buf2 = NULL; uint8_t *buf2 = NULL;
uint8_t *zero, *cur, *last; uint8_t *zero = NULL;
uint8_t *cur = NULL;
uint8_t *last = NULL;
JLSState *state = NULL; JLSState *state = NULL;
int i, size, ret; int i, size, ret;
int comps; int comps;
...@@ -272,7 +274,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, ...@@ -272,7 +274,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
buf2 = av_malloc(pkt->size); buf2 = av_malloc(pkt->size);
if (!buf2) if (!buf2)
goto fail; goto memfail;
init_put_bits(&pb, pkt->data, pkt->size); init_put_bits(&pb, pkt->data, pkt->size);
init_put_bits(&pb2, buf2, pkt->size); init_put_bits(&pb2, buf2, pkt->size);
...@@ -304,7 +306,8 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, ...@@ -304,7 +306,8 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
state = av_mallocz(sizeof(JLSState)); state = av_mallocz(sizeof(JLSState));
if (!state) if (!state)
goto fail; goto memfail;
/* initialize JPEG-LS state from JPEG parameters */ /* initialize JPEG-LS state from JPEG parameters */
state->near = near; state->near = near;
state->bpp = (avctx->pix_fmt == AV_PIX_FMT_GRAY16) ? 16 : 8; state->bpp = (avctx->pix_fmt == AV_PIX_FMT_GRAY16) ? 16 : 8;
...@@ -313,11 +316,10 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, ...@@ -313,11 +316,10 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
ls_store_lse(state, &pb); ls_store_lse(state, &pb);
zero = av_mallocz(FFABS(p->linesize[0])); zero = last = av_mallocz(FFABS(p->linesize[0]));
if (!zero) if (!zero)
goto fail; goto memfail;
last = zero;
cur = p->data[0]; cur = p->data[0];
if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) { if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
int t = 0; int t = 0;
...@@ -401,10 +403,12 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, ...@@ -401,10 +403,12 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
pkt->flags |= AV_PKT_FLAG_KEY; pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1; *got_packet = 1;
return 0; return 0;
fail:
memfail:
av_free_packet(pkt);
av_freep(&buf2); av_freep(&buf2);
av_freep(&state); av_freep(&state);
av_freep(&zero);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment