aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGanesh Ajjanagadde <gajjanagadde@gmail.com>2015-06-02 23:17:48 -0400
committerMichael Niedermayer <michaelni@gmx.at>2015-06-10 02:13:12 +0200
commit6d7384bd735b9e75f15af4639a102bdc9bdc2891 (patch)
treeaf5d37a86bcbea07cdee42cfa7c3df02c11ad6c0
parent9db97584ca5b1664f44f43f18546f78afd4db686 (diff)
downloadffmpeg-6d7384bd735b9e75f15af4639a102bdc9bdc2891.tar.gz
swresample/dither: check memory allocation
check memory allocation in swri_get_dither() Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 196b885a5f0aa3ca022c1fa99509f47341239784) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libswresample/dither.c6
-rw-r--r--libswresample/swresample.c3
-rw-r--r--libswresample/swresample_internal.h2
3 files changed, 8 insertions, 3 deletions
diff --git a/libswresample/dither.c b/libswresample/dither.c
index 8121f11c2f..23e7e12ede 100644
--- a/libswresample/dither.c
+++ b/libswresample/dither.c
@@ -23,12 +23,15 @@
#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));
int i;
+ if (!tmp)
+ return AVERROR(ENOMEM);
+
for(i=0; i<len + TMP_EXTRA; i++){
double v;
seed = seed* 1664525 + 1013904223;
@@ -70,6 +73,7 @@ void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSa
}
av_free(tmp);
+ return 0;
}
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 e866dc24e9..55f538a443 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -700,7 +700,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 108f837f23..96e1beac62 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -184,7 +184,7 @@ void swri_rematrix_free(SwrContext *s);
int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy);
void 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_arm(struct AudioConvert *ac,