From 87f63933f3f553dd01ba11d252ab3c23f4b3805e Mon Sep 17 00:00:00 2001
From: Pablo Rincon <pablo.rincon.crespo@gmail.com>
Date: Mon, 12 Apr 2010 13:20:33 +0200
Subject: [PATCH 4/6] Release the tmp prefix used for searching on the radix tree

---
 src/util-radix-tree.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/util-radix-tree.c b/src/util-radix-tree.c
index c7ac1be..122c0c4 100644
--- a/src/util-radix-tree.c
+++ b/src/util-radix-tree.c
@@ -1260,7 +1260,6 @@ static inline SCRadixNode *SCRadixFindKeyIPNetblock(SCRadixPrefix *prefix,
 
     if (node == NULL)
         return NULL;
-
     /* hold the node found containing a netmask.  We will need it when we call
      * this function recursively */
     netmask_node = node;
@@ -1341,12 +1340,16 @@ static SCRadixNode *SCRadixFindKey(uint8_t *key_stream, uint16_t key_bitlen,
             node = node->left;
         }
 
-        if (node == NULL)
+        if (node == NULL) {
+            SCRadixReleasePrefix(prefix, tree);
             return NULL;
+        }
     }
 
-    if (node->bit != prefix->bitlen || node->prefix == NULL)
+    if (node->bit != prefix->bitlen || node->prefix == NULL) {
+        SCRadixReleasePrefix(prefix, tree);
         return NULL;
+    }
 
     bytes = prefix->bitlen / 8;
     if (memcmp(node->prefix->stream, prefix->stream, bytes) == 0) {
@@ -1354,16 +1357,22 @@ static SCRadixNode *SCRadixFindKey(uint8_t *key_stream, uint16_t key_bitlen,
 
         if (prefix->bitlen % 8 == 0 ||
             (node->prefix->stream[bytes] & mask) == (prefix->stream[bytes] & mask)) {
-            if (SCRadixPrefixContainNetmaskAndSetUserData(node->prefix, key_bitlen, 1))
+            if (SCRadixPrefixContainNetmaskAndSetUserData(node->prefix, key_bitlen, 1)) {
+                SCRadixReleasePrefix(prefix, tree);
                 return node;
+            }
         }
     }
 
     /* if you are not an ip key, get out of here */
-    if (exact_match)
+    if (exact_match) {
+        SCRadixReleasePrefix(prefix, tree);
         return NULL;
+    }
 
-    return SCRadixFindKeyIPNetblock(prefix, node);
+    SCRadixNode *ret = SCRadixFindKeyIPNetblock(prefix, node);
+    SCRadixReleasePrefix(prefix, tree);
+    return ret;
 }
 
 /**
-- 
1.6.5

