summaryrefslogtreecommitdiff
path: root/libavcodec/g722enc.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-02-20 13:12:37 -0500
committerJustin Ruggles <justin.ruggles@gmail.com>2012-02-25 11:49:41 -0500
commit8e2555d3b1855374707a4d53bf93d3e07d61e05c (patch)
tree610c4e3b48b2d1898d44b50c0a0b879dcd25b502 /libavcodec/g722enc.c
parentca300d938bae4a35deaf668ef8349e396456fe0f (diff)
g722enc: check for trellis data allocation error
Diffstat (limited to 'libavcodec/g722enc.c')
-rw-r--r--libavcodec/g722enc.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index 1cb0070649..a5ae0a5153 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -41,9 +41,22 @@
#define MIN_TRELLIS 0
#define MAX_TRELLIS 16
+static av_cold int g722_encode_close(AVCodecContext *avctx)
+{
+ G722Context *c = avctx->priv_data;
+ int i;
+ for (i = 0; i < 2; i++) {
+ av_freep(&c->paths[i]);
+ av_freep(&c->node_buf[i]);
+ av_freep(&c->nodep_buf[i]);
+ }
+ return 0;
+}
+
static av_cold int g722_encode_init(AVCodecContext * avctx)
{
G722Context *c = avctx->priv_data;
+ int ret;
if (avctx->channels != 1) {
av_log(avctx, AV_LOG_ERROR, "Only mono tracks are allowed.\n");
@@ -62,6 +75,10 @@ static av_cold int g722_encode_init(AVCodecContext * avctx)
c->paths[i] = av_mallocz(max_paths * sizeof(**c->paths));
c->node_buf[i] = av_mallocz(2 * frontier * sizeof(**c->node_buf));
c->nodep_buf[i] = av_mallocz(2 * frontier * sizeof(**c->nodep_buf));
+ if (!c->paths[i] || !c->node_buf[i] || !c->nodep_buf[i]) {
+ ret = AVERROR(ENOMEM);
+ goto error;
+ }
}
}
@@ -100,18 +117,9 @@ static av_cold int g722_encode_init(AVCodecContext * avctx)
}
return 0;
-}
-
-static av_cold int g722_encode_close(AVCodecContext *avctx)
-{
- G722Context *c = avctx->priv_data;
- int i;
- for (i = 0; i < 2; i++) {
- av_freep(&c->paths[i]);
- av_freep(&c->node_buf[i]);
- av_freep(&c->nodep_buf[i]);
- }
- return 0;
+error:
+ g722_encode_close(avctx);
+ return ret;
}
static const int16_t low_quant[33] = {