summaryrefslogtreecommitdiff
path: root/libavcodec/resample2.c
diff options
context:
space:
mode:
authorMåns Rullgård <mans@mansr.com>2010-07-09 16:05:52 +0000
committerMåns Rullgård <mans@mansr.com>2010-07-09 16:05:52 +0000
commita426016cfc33dd7f68610358418e329fe8c8a410 (patch)
tree968a18c66a143732f42a989559b36b476115187e /libavcodec/resample2.c
parent603e5c0b711171fd0110745f4c1e650ac6c26760 (diff)
downloadffmpeg-a426016cfc33dd7f68610358418e329fe8c8a410.tar.gz
resample: check memory allocations in av_resample_init()
Originally committed as revision 24141 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/resample2.c')
-rw-r--r--libavcodec/resample2.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/libavcodec/resample2.c b/libavcodec/resample2.c
index 45f41a144c..05821eddb8 100644
--- a/libavcodec/resample2.c
+++ b/libavcodec/resample2.c
@@ -183,12 +183,17 @@ AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size,
double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
int phase_count= 1<<phase_shift;
+ if (!c)
+ return NULL;
+
c->phase_shift= phase_shift;
c->phase_mask= phase_count-1;
c->linear= linear;
c->filter_length= FFMAX((int)ceil(filter_size/factor), 1);
c->filter_bank= av_mallocz(c->filter_length*(phase_count+1)*sizeof(FELEM));
+ if (!c->filter_bank)
+ goto error;
build_filter(c->filter_bank, factor, c->filter_length, phase_count, 1<<FILTER_SHIFT, WINDOW_TYPE);
memcpy(&c->filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM));
c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1];
@@ -198,6 +203,9 @@ AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size,
c->index= -phase_count*((c->filter_length-1)/2);
return c;
+error:
+ av_free(c);
+ return NULL;
}
void av_resample_close(AVResampleContext *c){