From: Giuseppe Longo Date: Thu, 12 Dec 2013 22:03:42 +0000 (+0100) Subject: defrag-config: fix a bug X-Git-Tag: suricata-2.0beta2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8ba0fa7f92d01361baa1d3ed7c62d7a5a0c52b67;p=thirdparty%2Fsuricata.git defrag-config: fix a bug 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. --- diff --git a/src/defrag-config.c b/src/defrag-config.c index 1d8b28c924..d1b52a7c12 100644 --- a/src/defrag-config.c +++ b/src/defrag-config.c @@ -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.");