changeset 12120:a80468e73475 libavcodec

resample: check memory allocations in av_resample_init()
author mru
date Fri, 09 Jul 2010 16:05:52 +0000
parents 4530b6b4d931
children ee69b90df099
files resample2.c
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/resample2.c	Fri Jul 09 10:53:36 2010 +0000
+++ b/resample2.c	Fri Jul 09 16:05:52 2010 +0000
@@ -183,12 +183,17 @@
     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 @@
     c->index= -phase_count*((c->filter_length-1)/2);
 
     return c;
+error:
+    av_free(c);
+    return NULL;
 }
 
 void av_resample_close(AVResampleContext *c){