handle-memory-error.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
  2. index 83ad119..a3859e3 100644
  3. --- a/media/libspeex_resampler/src/resample.c
  4. +++ b/media/libspeex_resampler/src/resample.c
  5. @@ -811,6 +811,12 @@ EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
  6. return NULL;
  7. }
  8. st = (SpeexResamplerState *)speex_alloc(sizeof(SpeexResamplerState));
  9. + if (!st)
  10. + {
  11. + if (err)
  12. + *err = RESAMPLER_ERR_ALLOC_FAILED;
  13. + return NULL;
  14. + }
  15. st->initialised = 0;
  16. st->started = 0;
  17. st->in_rate = 0;
  18. @@ -832,9 +838,12 @@ EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
  19. st->buffer_size = 160;
  20. /* Per channel data */
  21. - st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t));
  22. - st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
  23. - st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
  24. + if (!(st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t))))
  25. + goto fail;
  26. + if (!(st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
  27. + goto fail;
  28. + if (!(st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
  29. + goto fail;
  30. for (i=0;i<nb_channels;i++)
  31. {
  32. st->last_sample[i] = 0;
  33. @@ -857,6 +866,12 @@ EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
  34. *err = filter_err;
  35. return st;
  36. +
  37. +fail:
  38. + if (err)
  39. + *err = RESAMPLER_ERR_ALLOC_FAILED;
  40. + speex_resampler_destroy(st);
  41. + return NULL;
  42. }
  43. EXPORT void speex_resampler_destroy(SpeexResamplerState *st)