]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm engine and ac mem free fixes
authorAnoop Saldanha <poonaatsoc@gmail.com>
Mon, 2 Jul 2012 16:54:37 +0000 (22:24 +0530)
committerVictor Julien <victor@inliniac.net>
Mon, 2 Jul 2012 18:56:03 +0000 (20:56 +0200)
src/detect-engine-mpm.c
src/util-mpm-ac.c

index aeddc04b450c6d92fe67fdd9fe6283434e05f254..909dd1ee9082812becc12720cf3cdc203cd2cc88 100644 (file)
@@ -886,6 +886,176 @@ void PatternMatchDestroyGroup(SigGroupHead *sh) {
         }
     }
 
+    if (sh->mpm_hcbd_ctx_ts != NULL || sh->mpm_hcbd_ctx_tc != NULL) {
+        if (sh->mpm_hcbd_ctx_ts != NULL) {
+            if (!sh->mpm_hcbd_ctx_ts->global) {
+                mpm_table[sh->mpm_hcbd_ctx_ts->mpm_type].DestroyCtx(sh->mpm_hcbd_ctx_ts);
+                SCFree(sh->mpm_hcbd_ctx_ts);
+            }
+            sh->mpm_hcbd_ctx_ts = NULL;
+        }
+        if (sh->mpm_hcbd_ctx_tc != NULL) {
+            if (!sh->mpm_hcbd_ctx_tc->global) {
+                mpm_table[sh->mpm_hcbd_ctx_tc->mpm_type].DestroyCtx(sh->mpm_hcbd_ctx_tc);
+                SCFree(sh->mpm_hcbd_ctx_tc);
+            }
+            sh->mpm_hcbd_ctx_tc = NULL;
+        }
+    }
+
+    if (sh->mpm_hsbd_ctx_ts != NULL || sh->mpm_hsbd_ctx_tc != NULL) {
+        if (sh->mpm_hsbd_ctx_ts != NULL) {
+            if (!sh->mpm_hsbd_ctx_ts->global) {
+                mpm_table[sh->mpm_hsbd_ctx_ts->mpm_type].DestroyCtx(sh->mpm_hsbd_ctx_ts);
+                SCFree(sh->mpm_hsbd_ctx_ts);
+            }
+            sh->mpm_hsbd_ctx_ts = NULL;
+        }
+        if (sh->mpm_hsbd_ctx_tc != NULL) {
+            if (!sh->mpm_hsbd_ctx_tc->global) {
+                mpm_table[sh->mpm_hsbd_ctx_tc->mpm_type].DestroyCtx(sh->mpm_hsbd_ctx_tc);
+                SCFree(sh->mpm_hsbd_ctx_tc);
+            }
+            sh->mpm_hsbd_ctx_tc = NULL;
+        }
+    }
+
+    if (sh->mpm_hhd_ctx_ts != NULL || sh->mpm_hhd_ctx_tc != NULL) {
+        if (sh->mpm_hhd_ctx_ts != NULL) {
+            if (!sh->mpm_hhd_ctx_ts->global) {
+                mpm_table[sh->mpm_hhd_ctx_ts->mpm_type].DestroyCtx(sh->mpm_hhd_ctx_ts);
+                SCFree(sh->mpm_hhd_ctx_ts);
+            }
+            sh->mpm_hhd_ctx_ts = NULL;
+        }
+        if (sh->mpm_hhd_ctx_tc != NULL) {
+            if (!sh->mpm_hhd_ctx_tc->global) {
+                mpm_table[sh->mpm_hhd_ctx_tc->mpm_type].DestroyCtx(sh->mpm_hhd_ctx_tc);
+                SCFree(sh->mpm_hhd_ctx_tc);
+            }
+            sh->mpm_hhd_ctx_tc = NULL;
+        }
+    }
+
+    if (sh->mpm_hrhd_ctx_ts != NULL || sh->mpm_hrhd_ctx_tc != NULL) {
+        if (sh->mpm_hrhd_ctx_ts != NULL) {
+            if (!sh->mpm_hrhd_ctx_ts->global) {
+                mpm_table[sh->mpm_hrhd_ctx_ts->mpm_type].DestroyCtx(sh->mpm_hrhd_ctx_ts);
+                SCFree(sh->mpm_hrhd_ctx_ts);
+            }
+            sh->mpm_hrhd_ctx_ts = NULL;
+        }
+        if (sh->mpm_hrhd_ctx_tc != NULL) {
+            if (!sh->mpm_hrhd_ctx_tc->global) {
+                mpm_table[sh->mpm_hrhd_ctx_tc->mpm_type].DestroyCtx(sh->mpm_hrhd_ctx_tc);
+                SCFree(sh->mpm_hrhd_ctx_tc);
+            }
+            sh->mpm_hrhd_ctx_tc = NULL;
+        }
+    }
+
+    if (sh->mpm_hmd_ctx_ts != NULL || sh->mpm_hmd_ctx_tc != NULL) {
+        if (sh->mpm_hmd_ctx_ts != NULL) {
+            if (!sh->mpm_hmd_ctx_ts->global) {
+                mpm_table[sh->mpm_hmd_ctx_ts->mpm_type].DestroyCtx(sh->mpm_hmd_ctx_ts);
+                SCFree(sh->mpm_hmd_ctx_ts);
+            }
+            sh->mpm_hmd_ctx_ts = NULL;
+        }
+        if (sh->mpm_hmd_ctx_tc != NULL) {
+            if (!sh->mpm_hmd_ctx_tc->global) {
+                mpm_table[sh->mpm_hmd_ctx_tc->mpm_type].DestroyCtx(sh->mpm_hmd_ctx_tc);
+                SCFree(sh->mpm_hmd_ctx_tc);
+            }
+            sh->mpm_hmd_ctx_tc = NULL;
+        }
+    }
+
+    if (sh->mpm_hcd_ctx_ts != NULL || sh->mpm_hcd_ctx_tc != NULL) {
+        if (sh->mpm_hcd_ctx_ts != NULL) {
+            if (!sh->mpm_hcd_ctx_ts->global) {
+                mpm_table[sh->mpm_hcd_ctx_ts->mpm_type].DestroyCtx(sh->mpm_hcd_ctx_ts);
+                SCFree(sh->mpm_hcd_ctx_ts);
+            }
+            sh->mpm_hcd_ctx_ts = NULL;
+        }
+        if (sh->mpm_hcd_ctx_tc != NULL) {
+            if (!sh->mpm_hcd_ctx_tc->global) {
+                mpm_table[sh->mpm_hcd_ctx_tc->mpm_type].DestroyCtx(sh->mpm_hcd_ctx_tc);
+                SCFree(sh->mpm_hcd_ctx_tc);
+            }
+            sh->mpm_hcd_ctx_tc = NULL;
+        }
+    }
+
+    if (sh->mpm_hrud_ctx_ts != NULL || sh->mpm_hrud_ctx_tc != NULL) {
+        if (sh->mpm_hrud_ctx_ts != NULL) {
+            if (!sh->mpm_hrud_ctx_ts->global) {
+                mpm_table[sh->mpm_hrud_ctx_ts->mpm_type].DestroyCtx(sh->mpm_hrud_ctx_ts);
+                SCFree(sh->mpm_hrud_ctx_ts);
+            }
+            sh->mpm_hrud_ctx_ts = NULL;
+        }
+        if (sh->mpm_hrud_ctx_tc != NULL) {
+            if (!sh->mpm_hrud_ctx_tc->global) {
+                mpm_table[sh->mpm_hrud_ctx_tc->mpm_type].DestroyCtx(sh->mpm_hrud_ctx_tc);
+                SCFree(sh->mpm_hrud_ctx_tc);
+            }
+            sh->mpm_hrud_ctx_tc = NULL;
+        }
+    }
+
+    if (sh->mpm_hsmd_ctx_ts != NULL || sh->mpm_hsmd_ctx_tc != NULL) {
+        if (sh->mpm_hsmd_ctx_ts != NULL) {
+            if (!sh->mpm_hsmd_ctx_ts->global) {
+                mpm_table[sh->mpm_hsmd_ctx_ts->mpm_type].DestroyCtx(sh->mpm_hsmd_ctx_ts);
+                SCFree(sh->mpm_hsmd_ctx_ts);
+            }
+            sh->mpm_hsmd_ctx_ts = NULL;
+        }
+        if (sh->mpm_hsmd_ctx_tc != NULL) {
+            if (!sh->mpm_hsmd_ctx_tc->global) {
+                mpm_table[sh->mpm_hsmd_ctx_tc->mpm_type].DestroyCtx(sh->mpm_hsmd_ctx_tc);
+                SCFree(sh->mpm_hsmd_ctx_tc);
+            }
+            sh->mpm_hsmd_ctx_tc = NULL;
+        }
+    }
+
+    if (sh->mpm_hscd_ctx_ts != NULL || sh->mpm_hscd_ctx_tc != NULL) {
+        if (sh->mpm_hscd_ctx_ts != NULL) {
+            if (!sh->mpm_hscd_ctx_ts->global) {
+                mpm_table[sh->mpm_hscd_ctx_ts->mpm_type].DestroyCtx(sh->mpm_hscd_ctx_ts);
+                SCFree(sh->mpm_hscd_ctx_ts);
+            }
+            sh->mpm_hscd_ctx_ts = NULL;
+        }
+        if (sh->mpm_hscd_ctx_tc != NULL) {
+            if (!sh->mpm_hscd_ctx_tc->global) {
+                mpm_table[sh->mpm_hscd_ctx_tc->mpm_type].DestroyCtx(sh->mpm_hscd_ctx_tc);
+                SCFree(sh->mpm_hscd_ctx_tc);
+            }
+            sh->mpm_hscd_ctx_tc = NULL;
+        }
+    }
+
+    if (sh->mpm_huad_ctx_ts != NULL || sh->mpm_huad_ctx_tc != NULL) {
+        if (sh->mpm_huad_ctx_ts != NULL) {
+            if (!sh->mpm_huad_ctx_ts->global) {
+                mpm_table[sh->mpm_huad_ctx_ts->mpm_type].DestroyCtx(sh->mpm_huad_ctx_ts);
+                SCFree(sh->mpm_huad_ctx_ts);
+            }
+            sh->mpm_huad_ctx_ts = NULL;
+        }
+        if (sh->mpm_huad_ctx_tc != NULL) {
+            if (!sh->mpm_huad_ctx_tc->global) {
+                mpm_table[sh->mpm_huad_ctx_tc->mpm_type].DestroyCtx(sh->mpm_huad_ctx_tc);
+                SCFree(sh->mpm_huad_ctx_tc);
+            }
+            sh->mpm_huad_ctx_tc = NULL;
+        }
+    }
+
     return;
 }
 
index dc520f11248609617262d7b3b0e518fe92c14d10..e6306e2aa62594bcc76ff07b4eda12a357fe1764 100644 (file)
@@ -234,6 +234,7 @@ static inline SCACPattern *SCACAllocPattern(MpmCtx *mpm_ctx)
  *
  * \param mpm_ctx Pointer to the mpm context.
  * \param p       Pointer to the SCACPattern instance to be freed.
+ * \param free    Free the above pointer or not.
  */
 static inline void SCACFreePattern(MpmCtx *mpm_ctx, SCACPattern *p)
 {
@@ -1174,6 +1175,25 @@ void SCACDestroyCtx(MpmCtx *mpm_ctx)
                                  sizeof(SC_AC_STATE_TYPE_U32) * 256);
     }
 
+    if (ctx->output_table != NULL) {
+        uint32_t state_count;
+        for (state_count = 0; state_count < ctx->state_count; state_count++) {
+            if (ctx->output_table[state_count].pids != NULL) {
+                SCFree(ctx->output_table[state_count].pids);
+            }
+        }
+        SCFree(ctx->output_table);
+    }
+
+    if (ctx->pid_pat_list != NULL) {
+        int i;
+        for (i = 0; i < (ctx->max_pat_id + 1); i++) {
+            if (ctx->pid_pat_list[i].cs != NULL)
+                SCFree(ctx->pid_pat_list[i].cs);
+        }
+        SCFree(ctx->pid_pat_list);
+    }
+
     SCFree(mpm_ctx->ctx);
     mpm_ctx->memory_cnt--;
     mpm_ctx->memory_size -= sizeof(SCACCtx);
@@ -2043,6 +2063,7 @@ static int SCACTest19(void)
         printf("1 != %" PRIu32 " ",cnt);
 
     SCACDestroyCtx(&mpm_ctx);
+    SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
     PmqFree(&pmq);
     return result;
 }