diff options
author | Jean-Yves Avenard <jyavenard@mozilla.com> | 2016-04-19 05:08:51 +0300 |
---|---|---|
committer | Tristan Matthews <tmatth@videolan.org> | 2016-05-10 21:48:31 +0300 |
commit | 8c2981fa4527330708fccda4de3490a60168d568 (patch) | |
tree | 1ff0dd69a13fddfa5642ae4279d5c83612696963 | |
parent | 13d02a0f66e25c7fbcfbb833ec534251e4ab59db (diff) |
Handle memory allocation failures during initialization
Signed-off-by: Tristan Matthews <tmatth@videolan.org>
-rw-r--r-- | libspeexdsp/resample.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/libspeexdsp/resample.c b/libspeexdsp/resample.c index 373d713..3c43b6d 100644 --- a/libspeexdsp/resample.c +++ b/libspeexdsp/resample.c @@ -792,6 +792,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; @@ -813,9 +819,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; @@ -838,6 +847,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) |