]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
defrag-config: fix a bug
authorGiuseppe Longo <giuseppelng@gmail.com>
Thu, 12 Dec 2013 22:03:42 +0000 (23:03 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 13 Dec 2013 12:27:17 +0000 (13:27 +0100)
A ptr to local var is stored in the radix tree currently,
this patch permits to alloc space to store host timeout
and thus also free it when data is removed.

src/defrag-config.c

index 1d8b28c924a9cda17a516a3d6a604fff6c7034af..d1b52a7c12741478e28479aa4fa238bee8bf5953 100644 (file)
@@ -34,19 +34,34 @@ static SCRadixTree *defrag_tree = NULL;
 
 static int default_timeout = 0;
 
-static void DefragPolicyAddHostInfo(char *host_ip_range, uint64_t *timeout)
+static void DefragPolicyFreeUserData(void *data)
 {
-    uint64_t *user_data = timeout;
+    if (data != NULL)
+        SCFree(data);
+
+    return;
+}
+
+static void DefragPolicyAddHostInfo(char *host_ip_range, uint64_t timeout)
+{
+    uint64_t *user_data = NULL;
+
+    if ( (user_data = SCMalloc(sizeof(uint64_t))) == NULL) {
+        SCLogError(SC_ERR_FATAL, "Error allocating memory. Exiting");
+        exit(EXIT_FAILURE);
+    }
+
+    *user_data = timeout;
 
     if (strchr(host_ip_range, ':') != NULL) {
         SCLogDebug("adding ipv6 host %s", host_ip_range);
-        if (SCRadixAddKeyIPV6String(host_ip_range, defrag_tree, user_data) == NULL) {
+        if (SCRadixAddKeyIPV6String(host_ip_range, defrag_tree, (void *)user_data) == NULL) {
             SCLogWarning(SC_ERR_INVALID_VALUE,
                         "failed to add ipv6 host %s", host_ip_range);
         }
     } else {
         SCLogDebug("adding ipv4 host %s", host_ip_range);
-        if (SCRadixAddKeyIPV4String(host_ip_range, defrag_tree, user_data) == NULL) {
+        if (SCRadixAddKeyIPV4String(host_ip_range, defrag_tree, (void *)user_data) == NULL) {
             SCLogWarning(SC_ERR_INVALID_VALUE,
                         "failed to add ipv4 host %s", host_ip_range);
         }
@@ -102,7 +117,7 @@ static void DefragParseParameters(ConfNode *n)
         if (strcasecmp("address", si->name) == 0) {
             ConfNode *pval;
             TAILQ_FOREACH(pval, &si->head, next) {
-                DefragPolicyAddHostInfo(pval->val, &timeout);
+                DefragPolicyAddHostInfo(pval->val, timeout);
             }
         }
     }
@@ -118,7 +133,7 @@ void DefragPolicyLoadFromConfig(void)
 {
     SCEnter();
 
-    defrag_tree = SCRadixCreateRadixTree(NULL, NULL);
+    defrag_tree = SCRadixCreateRadixTree(DefragPolicyFreeUserData, NULL);
     if (defrag_tree == NULL) {
         SCLogError(SC_ERR_MEM_ALLOC,
             "Can't alloc memory for the defrag config tree.");