changeset 202:5176462e2797

Fix potential memory leak
author Jamie Bullock <jamie@jamiebullock.com>
date Fri, 07 Mar 2014 21:42:46 +0000
parents ae2225b96ae1
children 302eab34dc88
files src/init.c
diffstat 1 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/init.c	Sun Feb 23 21:32:14 2014 +0000
+++ b/src/init.c	Fri Mar 07 21:42:46 2014 +0000
@@ -257,13 +257,36 @@
 
     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;