const int near = avctx->prediction_method;
PutBitContext pb, pb2;
GetBitContext gb;
- uint8_t *buf2, *zero, *cur, *last;
+ uint8_t *buf2 = NULL;
+ uint8_t *zero = NULL;
+ uint8_t *cur = NULL;
+ uint8_t *last = NULL;
JLSState *state;
int i, size, ret;
int comps;
}
buf2 = av_malloc(pkt->size);
+ if (!buf2)
+ goto memfail;
init_put_bits(&pb, pkt->data, pkt->size);
init_put_bits(&pb2, buf2, pkt->size);
put_bits(&pb, 8, 0); // point transform: none
state = av_mallocz(sizeof(JLSState));
+ if (!state)
+ goto memfail;
+
/* initialize JPEG-LS state from JPEG parameters */
state->near = near;
state->bpp = (avctx->pix_fmt == AV_PIX_FMT_GRAY16) ? 16 : 8;
ls_store_lse(state, &pb);
- zero = av_mallocz(p->linesize[0]);
- last = zero;
+ zero = last = av_mallocz(p->linesize[0]);
+ if (!zero)
+ goto memfail;
+
cur = p->data[0];
if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
int t = 0;
}
}
- av_free(zero);
- av_free(state);
+ av_freep(&zero);
+ av_freep(&state);
/* the specification says that after doing 0xff escaping unused bits in
* the last byte must be set to 0, so just append 7 "optional" zero-bits
}
}
avpriv_align_put_bits(&pb);
- av_free(buf2);
+ av_freep(&buf2);
/* End of image */
put_marker(&pb, EOI);
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
+
+memfail:
+ av_free_packet(pkt);
+ av_freep(&buf2);
+ av_freep(&state);
+ av_freep(&zero);
+ return AVERROR(ENOMEM);
}
static av_cold int encode_close(AVCodecContext *avctx)