Skip to content
Permalink
Browse files
Fix memleaks and double-free issues with xpath
  • Loading branch information
bblough committed Aug 18, 2018
1 parent cb81ab4 commit 2c740b48bafe401b7d189eb1c88c13cc9e60150d
Showing 4 changed files with 19 additions and 12 deletions.
@@ -66,9 +66,7 @@ axiom_xpath_compile_expression(

if (axiom_xpath_compile(env, expr) == AXIOM_XPATH_PARSE_ERROR)
{
AXIS2_FREE(env->allocator, expr->expr_str);
AXIS2_FREE(env->allocator, expr);

axiom_xpath_free_expression(env, expr);
return NULL;
}
else
@@ -371,7 +369,7 @@ axiom_xpath_free_context(
/* Free the expression if not freed */
if (context->expr)
{
/* axiom_xpath_free_expression(env, context->expr); */
axiom_xpath_free_expression(env, context->expr);

context->expr = NULL;
}
@@ -416,6 +414,15 @@ axiom_xpath_free_expression(

if (xpath_expr->operations)
{
axiom_xpath_operation_t *op = NULL;
while(axutil_array_list_size(xpath_expr->operations, env)) {
op = axutil_array_list_remove(xpath_expr->operations, env, 0);
if (op->par1)
AXIS2_FREE(env->allocator, op->par1);
if (op->par2)
AXIS2_FREE(env->allocator, op->par2);
AXIS2_FREE(env->allocator, op);
}
axutil_array_list_free(xpath_expr->operations, env);
xpath_expr->operations = NULL;
}
@@ -434,6 +441,11 @@ axiom_xpath_free_result(
{
if (result->nodes)
{
axiom_xpath_result_node_t *node = NULL;
while(axutil_array_list_size(result->nodes, env)) {
node = axutil_array_list_remove(result->nodes, env, 0);
AXIS2_FREE(env->allocator, node);
}
axutil_array_list_free(result->nodes, env);
}

@@ -52,6 +52,7 @@ axiom_xpath_run(
}

axutil_stack_free(context->stack, context->env);
context->stack = NULL;

return res;
}
@@ -45,8 +45,6 @@ axiom_xpath_compile(

if(expr->start == AXIOM_XPATH_PARSE_ERROR)
{
axutil_array_list_free(expr->operations, env);

return AXIOM_XPATH_PARSE_ERROR;
}
else
@@ -717,6 +715,7 @@ axiom_xpath_compile_step(
expr->expr_str + expr->expr_ptr);
#endif

AXIS2_FREE(env->allocator, node_test);
return AXIOM_XPATH_PARSE_ERROR;
}

@@ -1202,7 +1201,7 @@ axiom_xpath_compile_ncname(

name[i] = '\0';

return axutil_strdup(env, name);
return name;
}

/* Supporting functions */
@@ -274,11 +274,6 @@ void evaluate(
{
axiom_xpath_free_result(env, result);
}

if (expr)
{
axiom_xpath_free_expression(env, expr);
}
}

int compare_result(axis2_char_t *rs)

0 comments on commit 2c740b4

Please sign in to comment.