From: Ken Steele Date: Wed, 3 Dec 2014 20:55:22 +0000 (-0500) Subject: Fix memory leak in ac-tile X-Git-Tag: suricata-2.1beta3~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f86c5a83f7b4d936e7305fa67160623a4f2bea5;p=thirdparty%2Fsuricata.git Fix memory leak in ac-tile 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. --- diff --git a/src/util-mpm-ac-tile.c b/src/util-mpm-ac-tile.c index 0f270f24e0..b4735527bc 100644 --- a/src/util-mpm-ac-tile.c +++ b/src/util-mpm-ac-tile.c @@ -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));