[FFmpeg-devel] [PATCH 1/1] swresample/dither: check memory allocation

Ganesh Ajjanagadde gajjanagadde at gmail.com
Wed Jun 3 05:17:48 CEST 2015


check memory allocation in swri_get_dither()

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 libswresample/dither.c              | 5 ++++-
 libswresample/swresample.c          | 3 ++-
 libswresample/swresample_internal.h | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libswresample/dither.c b/libswresample/dither.c
index ca09e67..a027f46 100644
--- a/libswresample/dither.c
+++ b/libswresample/dither.c
@@ -23,10 +23,12 @@
 
 #include "noise_shaping_data.c"
 
-void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat noise_fmt) {
+int swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat noise_fmt) {
     double scale = s->dither.noise_scale;
 #define TMP_EXTRA 2
     double *tmp = av_malloc_array(len + TMP_EXTRA, sizeof(double));
+    if (!tmp)
+        return AVERROR(ENOMEM);
     int i;
 
     for(i=0; i<len + TMP_EXTRA; i++){
@@ -70,6 +72,7 @@ void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSa
     }
 
     av_free(tmp);
+    return 0;
 }
 
 av_cold int swri_dither_init(SwrContext *s, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt)
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 3d3ab83..87ad7f8 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -627,7 +627,8 @@ static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_co
                 return ret;
             if(ret)
                 for(ch=0; ch<s->dither.noise.ch_count; ch++)
-                    swri_get_dither(s, s->dither.noise.ch[ch], s->dither.noise.count, 12345678913579<<ch, s->dither.noise.fmt);
+                    if((ret=swri_get_dither(s, s->dither.noise.ch[ch], s->dither.noise.count, 12345678913579<<ch, s->dither.noise.fmt))<0)
+                        return ret;
             av_assert0(s->dither.noise.ch_count == preout->ch_count);
 
             if(s->dither.noise_pos + out_count > s->dither.noise.count)
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index 7296a3f..7745939 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -192,7 +192,7 @@ void swri_rematrix_free(SwrContext *s);
 int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy);
 int swri_rematrix_init_x86(struct SwrContext *s);
 
-void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat noise_fmt);
+int swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat noise_fmt);
 int swri_dither_init(SwrContext *s, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt);
 
 void swri_audio_convert_init_aarch64(struct AudioConvert *ac,
-- 
2.4.2



More information about the ffmpeg-devel mailing list