Fix double free after b19bfa1e20
This commit is contained in:
+1
@@ -63,6 +63,7 @@ typedef struct
|
||||
{
|
||||
AC_ALPHABET_t * astring; /* String of alphabets */
|
||||
unsigned int length; /* Length of pattern */
|
||||
u_int8_t is_existing; /* 1 if the node is already part of another AC_PATTERN_t */
|
||||
AC_REP_t rep; /* Representative string (optional) */
|
||||
} AC_PATTERN_t;
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -55,7 +55,7 @@ struct edge
|
||||
|
||||
AC_NODE_t * node_create (void);
|
||||
AC_NODE_t * node_create_next (AC_NODE_t * thiz, AC_ALPHABET_t alpha);
|
||||
void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str);
|
||||
void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str, u_int8_t is_existing);
|
||||
void node_register_outgoing (AC_NODE_t * thiz, AC_NODE_t * next, AC_ALPHABET_t alpha);
|
||||
AC_NODE_t * node_find_next (AC_NODE_t * thiz, AC_ALPHABET_t alpha);
|
||||
AC_NODE_t * node_findbs_next (AC_NODE_t * thiz, AC_ALPHABET_t alpha);
|
||||
|
||||
+2
-2
@@ -108,7 +108,7 @@ AC_ERROR_t ac_automata_add (AC_AUTOMATA_t * thiz, AC_PATTERN_t * patt)
|
||||
return ACERR_DUPLICATE_PATTERN;
|
||||
|
||||
n->final = 1;
|
||||
node_register_matchstr(n, patt);
|
||||
node_register_matchstr(n, patt, 0);
|
||||
thiz->total_patterns++;
|
||||
|
||||
return ACERR_SUCCESS;
|
||||
@@ -327,7 +327,7 @@ static void ac_automata_union_matchstrs (AC_NODE_t * node)
|
||||
while ((m = m->failure_node))
|
||||
{
|
||||
for (i=0; i < m->matched_patterns_num; i++)
|
||||
node_register_matchstr(node, &(m->matched_patterns[i]));
|
||||
node_register_matchstr(node, &(m->matched_patterns[i]), 1 /* this is an existing node */);
|
||||
|
||||
if (m->final)
|
||||
node->final = 1;
|
||||
|
||||
Vendored
+6
-3
@@ -76,8 +76,10 @@ void node_init(AC_NODE_t * thiz)
|
||||
void node_release(AC_NODE_t * thiz, u_int8_t free_pattern)
|
||||
{
|
||||
if(free_pattern) {
|
||||
for(int i=0; i<thiz->matched_patterns_num; i++)
|
||||
ndpi_free(thiz->matched_patterns[i].astring);
|
||||
for(int i=0; i<thiz->matched_patterns_num; i++) {
|
||||
if(!thiz->matched_patterns[i].is_existing)
|
||||
ndpi_free(thiz->matched_patterns[i].astring);
|
||||
}
|
||||
}
|
||||
|
||||
ndpi_free(thiz->matched_patterns);
|
||||
@@ -179,7 +181,7 @@ AC_NODE_t * node_create_next (AC_NODE_t * thiz, AC_ALPHABET_t alpha)
|
||||
* FUNCTION: node_register_matchstr
|
||||
* Adds the pattern to the list of accepted pattern.
|
||||
******************************************************************************/
|
||||
void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str)
|
||||
void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str, u_int8_t is_existing)
|
||||
{
|
||||
/* Check if the new pattern already exists in the node list */
|
||||
if (node_has_matchstr(thiz, str))
|
||||
@@ -197,6 +199,7 @@ void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str)
|
||||
|
||||
thiz->matched_patterns[thiz->matched_patterns_num].astring = str->astring;
|
||||
thiz->matched_patterns[thiz->matched_patterns_num].length = str->length;
|
||||
thiz->matched_patterns[thiz->matched_patterns_num].is_existing = is_existing;
|
||||
memcpy(&thiz->matched_patterns[thiz->matched_patterns_num].rep, &str->rep, sizeof(AC_REP_t));
|
||||
thiz->matched_patterns_num++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user