Skip to content

Commit

Permalink
xpath: trace and free complete xpath expression tree
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomaschewski committed Sep 24, 2018
1 parent e561f4c commit b0f3df4
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/xpath.c
Expand Up @@ -127,7 +127,7 @@ xpath_expression_parse(const char *expr)
failed:
ni_error("unable to parse XPATH expression \"%s\"", orig_expr);
if (tree)
xpath_enode_free(tree);
xpath_expression_free(tree);
return NULL;
}

Expand All @@ -149,18 +149,24 @@ xpath_expression_eval(const xpath_enode_t *enode, xml_node_t *xn)
/*
* Free a parsed XPATH expression
*/
void
xpath_expression_free(xpath_enode_t *enode)
static inline void
xpath_expr_free(xpath_enode_t *enode, unsigned int depth, const char *info)
{
if (!enode)
return;
if (enode->left)
xpath_enode_free(enode->left);
if (enode->right)
xpath_enode_free(enode->right);
xtrace("xpath_expression_free(%*.s%s %s %s)", depth, " ", info,
enode->ops ? enode->ops->name : NULL, enode->identifier);
xpath_expr_free(enode->left, depth + 2, "left ");
xpath_expr_free(enode->right, depth + 2, "right");
xpath_enode_free(enode);
}

void
xpath_expression_free(xpath_enode_t *enode)
{
xpath_expr_free(enode, 0, "expr ");
}

/*
* Convenience function: parse XPATH expression, evaluate it once,
* and return the resulting string.
Expand Down Expand Up @@ -442,7 +448,7 @@ __xpath_build_expr(const char **pp, char terminator, int infixprio)
failed:
/* ni_error("xpath: syntax error in expression \"%s\" at position %s", expr, pos); */
if (current)
xpath_enode_free(current);
xpath_expression_free(current);
return NULL;
}

Expand Down

0 comments on commit b0f3df4

Please sign in to comment.