]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Fix memory leak in ac-tile
authorKen Steele <ken@tilera.com>
Wed, 3 Dec 2014 20:55:22 +0000 (15:55 -0500)
committerVictor Julien <victor@inliniac.net>
Thu, 11 Dec 2014 10:53:46 +0000 (11:53 +0100)
Incorrectly reallocing the goto table after it was freed by calling
SCACTileReallocState() when really only want to realloc the output table.
This was causing a large goto table to be allocated and never used or
freed.

src/util-mpm-ac-tile.c

index 0f270f24e06fc935e97ad79bf823af8be2f5d879..b4735527bcf07ff1a196949abac7f275af4ab7fc 100644 (file)
@@ -523,32 +523,35 @@ error:
     return -1;
 }
 
-static void SCACTileReallocState(SCACTileCtx *ctx, int new_state_count)
+static void SCACTileReallocOutputTable(SCACTileCtx *ctx, int new_state_count)
 {
-    void *ptmp;
-    int size = 0;
 
-    /* reallocate space in the goto table to include a new state */
-    size = ctx->allocated_state_count * sizeof(int32_t) * 256;
-    ptmp = SCRealloc(ctx->goto_table, size);
+    /* reallocate space in the output table for the new state */
+    size_t size = ctx->allocated_state_count * sizeof(SCACTileOutputTable);
+    void *ptmp = SCRealloc(ctx->output_table, size);
     if (ptmp == NULL) {
-        SCFree(ctx->goto_table);
-        ctx->goto_table = NULL;
+        SCFree(ctx->output_table);
+        ctx->output_table = NULL;
         SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
         exit(EXIT_FAILURE);
     }
-    ctx->goto_table = ptmp;
+    ctx->output_table = ptmp;
+}
 
-    /* reallocate space in the output table for the new state */
-    size = ctx->allocated_state_count * sizeof(SCACTileOutputTable);
-    ptmp = SCRealloc(ctx->output_table, size);
+static void SCACTileReallocState(SCACTileCtx *ctx, int new_state_count)
+{
+    /* reallocate space in the goto table to include a new state */
+    size_t size = ctx->allocated_state_count * sizeof(int32_t) * 256;
+    void *ptmp = SCRealloc(ctx->goto_table, size);
     if (ptmp == NULL) {
-        SCFree(ctx->output_table);
-        ctx->output_table = NULL;
+        SCFree(ctx->goto_table);
+        ctx->goto_table = NULL;
         SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
         exit(EXIT_FAILURE);
     }
-    ctx->output_table = ptmp;
+    ctx->goto_table = ptmp;
+
+    SCACTileReallocOutputTable(ctx, new_state_count);
 }
 
 /**
@@ -1133,7 +1136,7 @@ static void SCACTilePrepareSearch(MpmCtx *mpm_ctx)
     SCACTileCtx *ctx = search_ctx->init_ctx;
 
     /* Resize the output table to be only as big as its final size. */
-    SCACTileReallocState(ctx, ctx->state_count);
+    SCACTileReallocOutputTable(ctx, ctx->state_count);
 
     search_ctx->search = ctx->search;
     memcpy(search_ctx->translate_table, ctx->translate_table, sizeof(ctx->translate_table));