]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Support freeing flow q handler out ctx. Adapt unittests to use the same
authorAnoop Saldanha <poonaatsoc@gmail.com>
Thu, 12 Jan 2012 11:23:02 +0000 (16:53 +0530)
committerVictor Julien <victor@inliniac.net>
Mon, 19 Mar 2012 11:55:41 +0000 (12:55 +0100)
src/tmqh-flow.c

index 7cd1072c2da4606d439afe30c2aed43fe6ef582c..038a8fd8d39fc9951a7d85bbf054d6f955e3b881 100644 (file)
@@ -44,6 +44,7 @@ void TmqhOutputFlowActiveFlows(ThreadVars *t, Packet *p);
 void TmqhOutputFlowActivePackets(ThreadVars *t, Packet *p);
 void TmqhOutputFlowRoundRobin(ThreadVars *t, Packet *p);
 void *TmqhOutputFlowSetupCtx(char *queue_str);
+void TmqhOutputFlowFreeCtx(void *ctx);
 void TmqhFlowRegisterTests(void);
 
 TmqhFlowCtx *tmqh_flow_outctx = NULL;
@@ -53,7 +54,7 @@ void TmqhFlowRegister(void)
     tmqh_table[TMQH_FLOW].name = "flow";
     tmqh_table[TMQH_FLOW].InHandler = TmqhInputFlow;
     tmqh_table[TMQH_FLOW].OutHandlerCtxSetup = TmqhOutputFlowSetupCtx;
-    tmqh_table[TMQH_FLOW].OutHandlerCtxFree = NULL;
+    tmqh_table[TMQH_FLOW].OutHandlerCtxFree = TmqhOutputFlowFreeCtx;
     tmqh_table[TMQH_FLOW].RegisterTests = TmqhFlowRegisterTests;
 
     char *scheduler = NULL;
@@ -194,6 +195,22 @@ error:
     return NULL;
 }
 
+void TmqhOutputFlowFreeCtx(void *ctx)
+{
+    int i;
+    TmqhFlowCtx *fctx = (TmqhFlowCtx *)ctx;
+
+    for (i = 0; i < fctx->size; i++) {
+        SC_ATOMIC_DESTROY(fctx->queues[i].active_flows);
+    }
+
+    SCFree(fctx->queues);
+
+    tmqh_flow_outctx = NULL;
+
+    return;
+}
+
 /**
  * \brief select the queue to output in a round robin fashion.
  *
@@ -398,6 +415,8 @@ static int TmqhOutputFlowSetupCtxTest01(void)
 
     retval = 1;
 end:
+    if (fctx != NULL)
+        TmqhOutputFlowFreeCtx(fctx);
     TmqResetQueues();
     return retval;
 }
@@ -441,6 +460,8 @@ static int TmqhOutputFlowSetupCtxTest02(void)
 
     retval = 1;
 end:
+    if (fctx != NULL)
+        TmqhOutputFlowFreeCtx(fctx);
     TmqResetQueues();
     return retval;
 }
@@ -476,6 +497,8 @@ static int TmqhOutputFlowSetupCtxTest03(void)
 
     retval = 1;
 end:
+    if (fctx != NULL)
+        TmqhOutputFlowFreeCtx(fctx);
     TmqResetQueues();
     return retval;
 }