From eb9e72e645583932d0b3010e7d49a16e55170f04 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 3 Sep 2013 01:19:16 +0000 Subject: add more error handling --- fft.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fft.c b/fft.c index 1e0e426..d178a84 100644 --- a/fft.c +++ b/fft.c @@ -46,19 +46,26 @@ hamming(size_t n) return w; } +double * +fft_realloc(double *p, size_t n) +{ + if (p) + fftw_free(p); + p = fftw_malloc(n * sizeof(double)); + if (!p) + errx(1, "malloc failed"); + + return p; +} + struct fft * resize_fft(struct fft *p, size_t n) { if (n != p->n) { p->n = n; - if (p->in) - fftw_free(p->in); - p->in = fftw_malloc(p->n * sizeof(double)); - - if (p->out) - fftw_free(p->out); - p->out = fftw_malloc(p->n * sizeof(double)); + p->in = fft_realloc(p->in, p->n); + p->out = fft_realloc(p->out, p->n); if (p->window) free(p->window); -- cgit v1.2.3