Author: billblough
Date: Mon Dec 3 01:52:51 2018
New Revision: 1848018
URL: http://svn.apache.org/viewvc?rev=1848018&view=rev
Log:
More xpath memory fixes
Fix several memory leaks and free issues.
Includes additional fixes for AXISC-1602 and parts of AXISC-1669
Modified:
axis/axis2/c/core/trunk/axiom/src/xpath/xpath.c
axis/axis2/c/core/trunk/axiom/src/xpath/xpath_functions.c
axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals.c
axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_parser.c
axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc
Modified: axis/axis2/c/core/trunk/axiom/src/xpath/xpath.c
URL:
http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/src/xpath/xpath.c?rev=1848018&r1=1848017&r2=1848018&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/src/xpath/xpath.c (original)
+++ axis/axis2/c/core/trunk/axiom/src/xpath/xpath.c Mon Dec 3 01:52:51 2018
@@ -393,6 +393,12 @@ axiom_xpath_free_context(
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 @@ axiom_xpath_free_expression(
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 @@ 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);
+ 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_free_result(
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);
}
Modified: axis/axis2/c/core/trunk/axiom/src/xpath/xpath_functions.c
URL:
http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/src/xpath/xpath_functions.c?rev=1848018&r1=1848017&r2=1848018&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/src/xpath/xpath_functions.c (original)
+++ axis/axis2/c/core/trunk/axiom/src/xpath/xpath_functions.c Mon Dec 3
01:52:51 2018
@@ -37,7 +37,7 @@ axiom_xpath_function_count(
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);
Modified: axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals.c
URL:
http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals.c?rev=1848018&r1=1848017&r2=1848018&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals.c (original)
+++ axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals.c Mon Dec 3
01:52:51 2018
@@ -27,6 +27,9 @@ axiom_xpath_expression_copy(
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 */
Modified: axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_parser.c
URL:
http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_parser.c?rev=1848018&r1=1848017&r2=1848018&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_parser.c (original)
+++ axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_parser.c Mon Dec 3
01:52:51 2018
@@ -404,15 +404,19 @@ axiom_xpath_compile_path_expression(
/* 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 @@ axiom_xpath_compile_step(
{
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 @@ axiom_xpath_compile_step(
axis = AXIOM_XPATH_AXIS_CHILD;
expr->expr_ptr = temp_ptr;
}
+ AXIS2_FREE(env->allocator, name);
}
else
@@ -740,6 +746,7 @@ axiom_xpath_compile_node_test(
{
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 @@ axiom_xpath_compile_function_call(
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 @@ axiom_xpath_compile_literal(
lit[i] = '\0';
- return lit;
+ if (strlen(lit))
+ return axutil_strdup(env, lit);
+ else
+ return NULL;
}
@@ -1129,7 +1140,10 @@ axiom_xpath_compile_ncname(
name[i] = '\0';
- return name;
+ if (strlen(name))
+ return axutil_strdup(env, name);
+ else
+ return NULL;
}
/* Supporting functions */
Modified: axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc
URL:
http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc?rev=1848018&r1=1848017&r2=1848018&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc (original)
+++ axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc Mon Dec 3
01:52:51 2018
@@ -369,6 +369,7 @@ void output_results(const axutil_env_t *
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)