axis-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billblo...@apache.org
Subject svn commit: r1838343 - in /axis/axis2/c/core/trunk/axiom: src/xpath/xpath.c src/xpath/xpath_internals_engine.c src/xpath/xpath_internals_parser.c test/xpath/test_xpath.cc
Date Sat, 18 Aug 2018 16:12:17 GMT
Author: billblough
Date: Sat Aug 18 16:12:16 2018
New Revision: 1838343

URL: http://svn.apache.org/viewvc?rev=1838343&view=rev
Log:
Fix memleaks and double-free issues with xpath

Modified:
    axis/axis2/c/core/trunk/axiom/src/xpath/xpath.c
    axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_engine.c
    axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_parser.c
    axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.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=1838343&r1=1838342&r2=1838343&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/src/xpath/xpath.c (original)
+++ axis/axis2/c/core/trunk/axiom/src/xpath/xpath.c Sat Aug 18 16:12:16 2018
@@ -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);
         }
 

Modified: axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_engine.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_engine.c?rev=1838343&r1=1838342&r2=1838343&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_engine.c (original)
+++ axis/axis2/c/core/trunk/axiom/src/xpath/xpath_internals_engine.c Sat Aug 18 16:12:16 2018
@@ -52,6 +52,7 @@ axiom_xpath_run(
     }
 
     axutil_stack_free(context->stack, context->env);
+    context->stack = NULL;
 
     return res;
 }

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=1838343&r1=1838342&r2=1838343&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 Sat Aug 18 16:12:16 2018
@@ -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 */

Modified: axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.cc?rev=1838343&r1=1838342&r2=1838343&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.cc (original)
+++ axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.cc Sat Aug 18 16:12:16 2018
@@ -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)



Mime
View raw message