[FFmpeg-cvslog] nellymoserenc: improve error checking in encode_init()

Justin Ruggles git at videolan.org
Sun Feb 26 05:21:46 CET 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Tue Feb 21 18:46:00 2012 -0500| [370b44cda2230cf839f7c3849a3b881650fe1bd8] | committer: Justin Ruggles

nellymoserenc: improve error checking in encode_init()

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=370b44cda2230cf839f7c3849a3b881650fe1bd8
---

 libavcodec/nellymoserenc.c |   40 ++++++++++++++++++++++++----------------
 1 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index 81e1d37..4f351da 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -127,10 +127,24 @@ static void apply_mdct(NellyMoserEncodeContext *s)
     s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN);
 }
 
+static av_cold int encode_end(AVCodecContext *avctx)
+{
+    NellyMoserEncodeContext *s = avctx->priv_data;
+
+    ff_mdct_end(&s->mdct_ctx);
+
+    if (s->avctx->trellis) {
+        av_free(s->opt);
+        av_free(s->path);
+    }
+
+    return 0;
+}
+
 static av_cold int encode_init(AVCodecContext *avctx)
 {
     NellyMoserEncodeContext *s = avctx->priv_data;
-    int i;
+    int i, ret;
 
     if (avctx->channels != 1) {
         av_log(avctx, AV_LOG_ERROR, "Nellymoser supports only 1 channel\n");
@@ -147,7 +161,8 @@ static av_cold int encode_init(AVCodecContext *avctx)
 
     avctx->frame_size = NELLY_SAMPLES;
     s->avctx = avctx;
-    ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0);
+    if ((ret = ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0)) < 0)
+        goto error;
     ff_dsputil_init(&s->dsp, avctx);
 
     /* Generate overlap window */
@@ -158,23 +173,16 @@ static av_cold int encode_init(AVCodecContext *avctx)
     if (s->avctx->trellis) {
         s->opt  = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float  ));
         s->path = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(uint8_t));
+        if (!s->opt || !s->path) {
+            ret = AVERROR(ENOMEM);
+            goto error;
+        }
     }
 
     return 0;
-}
-
-static av_cold int encode_end(AVCodecContext *avctx)
-{
-    NellyMoserEncodeContext *s = avctx->priv_data;
-
-    ff_mdct_end(&s->mdct_ctx);
-
-    if (s->avctx->trellis) {
-        av_free(s->opt);
-        av_free(s->path);
-    }
-
-    return 0;
+error:
+    encode_end(avctx);
+    return ret;
 }
 
 #define find_best(val, table, LUT, LUT_add, LUT_size) \



More information about the ffmpeg-cvslog mailing list