From 43482939ccd1a73a359191524a851dbab14743d0 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Fri, 7 Mar 2014 21:42:46 +0000 Subject: Fix potential memory leak --- src/init.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/init.c b/src/init.c index 10c5535..b858a19 100644 --- a/src/init.c +++ b/src/init.c @@ -257,13 +257,36 @@ int xtract_init_mfcc(int N, double nyquist, int style, double freq_min, double f mel_peak = (double *)malloc((freq_bands + 2) * sizeof(double)); /* +2 for zeros at start and end */ + + if (mel_peak == NULL) + { + perror("error"); + return XTRACT_MALLOC_FAILED; + } + lin_peak = (double *)malloc((freq_bands + 2) * sizeof(double)); + + if (lin_peak == NULL) + { + perror("error"); + return XTRACT_MALLOC_FAILED; + } + fft_peak = (int *)malloc((freq_bands + 2) * sizeof(int)); + + if (fft_peak == NULL) + { + perror("error"); + return XTRACT_MALLOC_FAILED; + } + height_norm = (double *)malloc(freq_bands * sizeof(double)); - - if(mel_peak == NULL || height_norm == NULL || - lin_peak == NULL || fft_peak == NULL) + + if (height_norm == NULL) + { + perror("error"); return XTRACT_MALLOC_FAILED; + } M = N >> 1; -- cgit v1.2.3