DetectEngineAppInspectionEngine *t = g_app_inspect_engines;
while (t != NULL) {
- if (s->init_data->smlists[t->sm_list] == NULL)
+ if (s->sm_arrays[t->sm_list] == NULL)
goto next;
if (t->alproto == ALPROTO_UNKNOWN) {
/* special case, inspect engine applies to all protocols */
t = t->next;
}
+ /* clear s->sm_arrays for those lists that we put
+ * in the inspect engines. They own it now. */
int i;
for (i = 0; i < DETECT_SM_LIST_MAX; i++) {
if (lists_used[i]) {
{
SigMatchData *ptrs[DETECT_SM_LIST_MAX] = { NULL };
+ /* free engines and put smd in the array */
DetectEngineAppInspectionEngine *ie = s->app_inspect;
while (ie) {
DetectEngineAppInspectionEngine *next = ie->next;
ie = next;
}
+ /* free the smds */
int i;
for (i = 0; i < DETECT_SM_LIST_MAX; i++)
{
+ if (ptrs[i] == NULL)
+ continue;
+
+ SigMatchData *smd = ptrs[i];
+ while(1) {
+ if (sigmatch_table[smd->type].Free != NULL) {
+ sigmatch_table[smd->type].Free(smd->ctx);
+ }
+ if (smd->is_last)
+ break;
+ smd++;
+ }
SCFree(ptrs[i]);
}
}
SCReturn;
}
-static void SigMatchFreeArrays(Signature *s)
+static void SigMatchFreeArrays(Signature *s, int ctxs)
{
if (s != NULL) {
int type;
for (type = 0; type < DETECT_SM_LIST_MAX; type++) {
- if (s->sm_arrays[type] != NULL)
+ if (s->sm_arrays[type] != NULL) {
+ if (ctxs) {
+ SigMatchData *smd = s->sm_arrays[type];
+ while(1) {
+ if (sigmatch_table[smd->type].Free != NULL) {
+ sigmatch_table[smd->type].Free(smd->ctx);
+ }
+ if (smd->is_last)
+ break;
+ smd++;
+ }
+ }
+
SCFree(s->sm_arrays[type]);
+ }
}
}
}
}
}
}
- SigMatchFreeArrays(s);
+ SigMatchFreeArrays(s, (s->init_data == NULL));
+ if (s->init_data) {
+ SCFree(s->init_data);
+ s->init_data = NULL;
+ }
if (s->sp != NULL) {
DetectPortCleanupList(s->sp);
return len;
}
+/** \internal
+ * \brief perform final per signature setup tasks
+ *
+ * - Create SigMatchData arrays from the init only SigMatch lists
+ * - Setup per signature inspect engines
+ * - remove signature init data.
+ */
static int SigMatchPrepare(DetectEngineCtx *de_ctx)
{
SCEnter();
for (; sm != NULL; sm = sm->next, smd++) {
smd->type = sm->type;
smd->ctx = sm->ctx;
+ sm->ctx = NULL; // SigMatch no longer owns the ctx
smd->is_last = (sm->next == NULL);
}
}
}
+
+ /* set up inspect engines */
DetectEngineAppInspectionEngine2Signature(s);
- /* TODO free lists etc */
+ /* free lists. Ctx' are xferred to sm_arrays so won't get freed */
+ int i;
+ for (i = 0; i < DETECT_SM_LIST_MAX; i++) {
+ SigMatch *sm = s->init_data->smlists[i];
+ while (sm != NULL) {
+ SigMatch *nsm = sm->next;
+ SigMatchFree(sm);
+ sm = nsm;
+ }
+ }
SCFree(s->init_data);
s->init_data = NULL;
}