More xpath memory fixes
Fix several memory leaks and free issues.
Includes additional fixes for AXISC-1602 and parts of AXISC-1669
diff --git a/axiom/src/xpath/xpath.c b/axiom/src/xpath/xpath.c
index 866d4f5..95c3656 100755
--- a/axiom/src/xpath/xpath.c
+++ b/axiom/src/xpath/xpath.c
@@ -393,6 +393,12 @@
context->namespaces = NULL;
}
+ if(context->attribute)
+ {
+ axiom_attribute_free(context->attribute, context->env);
+ context->attribute = NULL;
+ }
+
AXIS2_FREE(env->allocator, context);
}
}
@@ -403,6 +409,11 @@
const axutil_env_t *env,
axiom_xpath_expression_t * xpath_expr)
{
+ int num = 0;
+ int i = 0;
+ axiom_xpath_operation_t * op = NULL;
+ axiom_xpath_node_test_t * node_test = NULL;
+
if (xpath_expr)
{
if (xpath_expr->expr_str)
@@ -414,20 +425,57 @@
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);
+ num = axutil_array_list_size(xpath_expr->operations, env);
+ for (i=0; i<num; i++)
+ {
+ op = (axiom_xpath_operation_t *) axutil_array_list_get(xpath_expr->operations, env, i);
+ if (op)
+ {
+ if(op->opr)
+ {
+ if (op->opr != AXIOM_XPATH_OPERATION_LITERAL)
+ {
+ if ((op->par1) && (op->par1 != AXIOM_XPATH_PARSE_END))
+ {
+ node_test = (axiom_xpath_node_test_t *)op->par1;
+ if (node_test)
+ {
+ if (node_test->type >= 1 && node_test->type <= 6)
+ {
+ if (node_test->name)
+ {
+ AXIS2_FREE(env->allocator, node_test->name);
+ }
+
+ if (node_test->prefix)
+ {
+ AXIS2_FREE(env->allocator, node_test->prefix);
+ }
+
+ if (node_test->lit)
+ {
+ AXIS2_FREE(env->allocator, node_test->lit);
+ }
+ }
+ }
+ }
+ }
+ AXIS2_FREE(env->allocator, op->par1);
+ }
+
+ if ((op->par2) && (op->par2 != AXIOM_XPATH_PARSE_END))
+ {
+ AXIS2_FREE(env->allocator, op->par2);
+ }
+ AXIS2_FREE(env->allocator, op);
+ }
}
axutil_array_list_free(xpath_expr->operations, env);
xpath_expr->operations = NULL;
}
AXIS2_FREE(env->allocator, xpath_expr);
+ xpath_expr = NULL;
}
}
@@ -444,7 +492,19 @@
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);
+ if (node)
+ {
+ if (node->value)
+ {
+ if (node->type != AXIOM_XPATH_TYPE_NODE &&
+ node->type != AXIOM_XPATH_TYPE_ATTRIBUTE &&
+ node->type != AXIOM_XPATH_TYPE_NAMESPACE)
+ {
+ AXIS2_FREE(env->allocator, node->value);
+ }
+ }
+ AXIS2_FREE(env->allocator, node);
+ }
}
axutil_array_list_free(result->nodes, env);
}
diff --git a/axiom/src/xpath/xpath_functions.c b/axiom/src/xpath/xpath_functions.c
index bdf65c2..f242db7 100755
--- a/axiom/src/xpath/xpath_functions.c
+++ b/axiom/src/xpath/xpath_functions.c
@@ -37,7 +37,7 @@
for(i = 0; i < np; i++)
{
- axutil_stack_pop(context->stack, context->env);
+ AXIS2_FREE(context->env->allocator, axutil_stack_pop(context->stack, context->env));
}
axutil_stack_push(context->stack, context->env, node);
diff --git a/axiom/src/xpath/xpath_internals.c b/axiom/src/xpath/xpath_internals.c
index c313baf..f71d32a 100755
--- a/axiom/src/xpath/xpath_internals.c
+++ b/axiom/src/xpath/xpath_internals.c
@@ -27,6 +27,9 @@
int i;
axiom_xpath_operation_t *op;
+ if (context->expr)
+ axiom_xpath_free_expression(context->env, context->expr);
+
context->expr = expr;
/* Set value of pos in every operation to 0 */
diff --git a/axiom/src/xpath/xpath_internals_parser.c b/axiom/src/xpath/xpath_internals_parser.c
index f74375f..c3f58c7 100755
--- a/axiom/src/xpath/xpath_internals_parser.c
+++ b/axiom/src/xpath/xpath_internals_parser.c
@@ -404,15 +404,19 @@
/* If node type */
if(axutil_strcmp(name, node_types[i]) == 0)
{
+ AXIS2_FREE(env->allocator, name);
return axiom_xpath_compile_location_path(env, expr);
}
}
+ AXIS2_FREE(env->allocator, name);
return axiom_xpath_path_compile_path_expression_filter(env, expr);
}
expr->expr_ptr = temp_ptr;
+ if(name)
+ AXIS2_FREE(env->allocator, name);
return axiom_xpath_compile_location_path(env, expr);
}
@@ -625,6 +629,7 @@
{
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
"Parse error: Invalid axis - %s", name);
+ AXIS2_FREE(env->allocator, name);
return AXIOM_XPATH_PARSE_ERROR;
}
@@ -636,6 +641,7 @@
axis = AXIOM_XPATH_AXIS_CHILD;
expr->expr_ptr = temp_ptr;
}
+ AXIS2_FREE(env->allocator, name);
}
else
@@ -740,6 +746,7 @@
{
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
"Parse error: Invalid node type - %s", name);
+ AXIS2_FREE(env->allocator, name);
AXIS2_FREE(env->allocator, node_test);
return NULL;
@@ -829,6 +836,7 @@
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
"Parse error: ')' expected - %s",
expr->expr_str + expr->expr_ptr);
+ AXIS2_FREE(env->allocator, name);
return AXIOM_XPATH_PARSE_ERROR;
}
@@ -972,7 +980,10 @@
lit[i] = '\0';
- return lit;
+ if (strlen(lit))
+ return axutil_strdup(env, lit);
+ else
+ return NULL;
}
@@ -1129,7 +1140,10 @@
name[i] = '\0';
- return name;
+ if (strlen(name))
+ return axutil_strdup(env, name);
+ else
+ return NULL;
}
/* Supporting functions */
diff --git a/axiom/test/xpath/test_xpath_streaming.cc b/axiom/test/xpath/test_xpath_streaming.cc
index 41ee48e..b93a8a9 100644
--- a/axiom/test/xpath/test_xpath_streaming.cc
+++ b/axiom/test/xpath/test_xpath_streaming.cc
@@ -369,6 +369,7 @@
sprintf(temp_res, "\"%s\"\n", result_str);
strcat(result_set, temp_res);
+ AXIS2_FREE(env->allocator, result_str);
}
}
else if (xpath_result_node->type == AXIOM_XPATH_TYPE_ATTRIBUTE)