Bug 1264199: [speex] P7. Handle memory allocation failures during initialization. r=kinetik
☠☠ backed out by 6ebd803604bb ☠ ☠
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 19 Apr 2016 14:39:39 +1000
changeset 332151 a9bfe66b235c0936cb34f53d24aee08d3814bdfd
parent 332150 b83be2d0614b80d56b603d0f9311419d1edc78ad
child 332152 b52399a4a1750d6819cfac993c8c732d5e643a1d
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1264199
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1264199: [speex] P7. Handle memory allocation failures during initialization. r=kinetik Fix submitted upstream. MozReview-Commit-ID: JpHoVKu2S7w
media/libspeex_resampler/handle-memory-error.patch
media/libspeex_resampler/src/resample.c
media/libspeex_resampler/update.sh
new file mode 100644
--- /dev/null
+++ b/media/libspeex_resampler/handle-memory-error.patch
@@ -0,0 +1,46 @@
+diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
+index 83ad119..a3859e3 100644
+--- a/media/libspeex_resampler/src/resample.c
++++ b/media/libspeex_resampler/src/resample.c
+@@ -811,6 +811,12 @@ EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
+       return NULL;
+    }
+    st = (SpeexResamplerState *)speex_alloc(sizeof(SpeexResamplerState));
++   if (!st)
++   {
++      if (err)
++         *err = RESAMPLER_ERR_ALLOC_FAILED;
++      return NULL;
++   }
+    st->initialised = 0;
+    st->started = 0;
+    st->in_rate = 0;
+@@ -832,9 +838,12 @@ EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
+    st->buffer_size = 160;
+    
+    /* Per channel data */
+-   st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t));
+-   st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
+-   st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
++   if (!(st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t))))
++      goto fail;
++   if (!(st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
++      goto fail;
++   if (!(st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
++      goto fail;
+    for (i=0;i<nb_channels;i++)
+    {
+       st->last_sample[i] = 0;
+@@ -857,6 +866,12 @@ EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
+       *err = filter_err;
+ 
+    return st;
++
++fail:
++   if (err)
++      *err = RESAMPLER_ERR_ALLOC_FAILED;
++   speex_resampler_destroy(st);
++   return NULL;
+ }
+ 
+ EXPORT void speex_resampler_destroy(SpeexResamplerState *st)
--- a/media/libspeex_resampler/src/resample.c
+++ b/media/libspeex_resampler/src/resample.c
@@ -806,16 +806,22 @@ EXPORT SpeexResamplerState *speex_resamp
 
    if (quality > 10 || quality < 0)
    {
       if (err)
          *err = RESAMPLER_ERR_INVALID_ARG;
       return NULL;
    }
    st = (SpeexResamplerState *)speex_alloc(sizeof(SpeexResamplerState));
+   if (!st)
+   {
+      if (err)
+         *err = RESAMPLER_ERR_ALLOC_FAILED;
+      return NULL;
+   }
    st->initialised = 0;
    st->started = 0;
    st->in_rate = 0;
    st->out_rate = 0;
    st->num_rate = 0;
    st->den_rate = 0;
    st->quality = -1;
    st->sinc_table_length = 0;
@@ -827,19 +833,22 @@ EXPORT SpeexResamplerState *speex_resamp
    st->cutoff = 1.f;
    st->nb_channels = nb_channels;
    st->in_stride = 1;
    st->out_stride = 1;
    
    st->buffer_size = 160;
    
    /* Per channel data */
-   st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t));
-   st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
-   st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
+   if (!(st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t))))
+      goto fail;
+   if (!(st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
+      goto fail;
+   if (!(st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
+      goto fail;
    for (i=0;i<nb_channels;i++)
    {
       st->last_sample[i] = 0;
       st->magic_samples[i] = 0;
       st->samp_frac_num[i] = 0;
    }
 
    speex_resampler_set_quality(st, quality);
@@ -852,16 +861,22 @@ EXPORT SpeexResamplerState *speex_resamp
    } else {
       speex_resampler_destroy(st);
       st = NULL;
    }
    if (err)
       *err = filter_err;
 
    return st;
+
+fail:
+   if (err)
+      *err = RESAMPLER_ERR_ALLOC_FAILED;
+   speex_resampler_destroy(st);
+   return NULL;
 }
 
 EXPORT void speex_resampler_destroy(SpeexResamplerState *st)
 {
    speex_free(st->mem);
    speex_free(st->sinc_table);
    speex_free(st->last_sample);
    speex_free(st->magic_samples);
--- a/media/libspeex_resampler/update.sh
+++ b/media/libspeex_resampler/update.sh
@@ -20,8 +20,9 @@ cp $1/AUTHORS .
 cp $1/COPYING .
 
 # apply outstanding local patches
 patch -p3 < outside-speex.patch
 patch -p3 < simd-detect-runtime.patch
 patch -p3 < set-skip-frac.patch
 patch -p3 < hugemem.patch
 patch -p3 < remove-empty-asm-clobber.patch
+patch -p3 < handle-memory-error.patch