Optimize memory allocation to use alloca when possible.
[gnulib.git] / lib / c-strcasestr.c
index 6c372e0..9e0cd38 100644 (file)
@@ -25,6 +25,7 @@
 #include <stddef.h>
 #include <string.h>
 
+#include "allocsa.h"
 #include "c-ctype.h"
 
 /* Knuth-Morris-Pratt algorithm.
@@ -37,7 +38,7 @@ knuth_morris_pratt (const char *haystack, const char *needle,
   size_t m = strlen (needle);
 
   /* Allocate the table.  */
-  size_t *table = (size_t *) malloc (m * sizeof (size_t));
+  size_t *table = (size_t *) allocsa (m * sizeof (size_t));
   if (table == NULL)
     return false;
   /* Fill the table.
@@ -112,7 +113,7 @@ knuth_morris_pratt (const char *haystack, const char *needle,
        }
   }
 
-  free (table);
+  freesa (table);
   return true;
 }