You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-commits@axis.apache.org by ro...@apache.org on 2026/01/15 13:06:27 UTC

(axis-axis2-c-core) 02/02: AXIS2C-1596: Fix memory leaks in JSON reader

This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-c-core.git

commit 4ea7d28fc02c899a9d7cf1407607ce51aa6f0601
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Thu Jan 15 03:04:13 2026 -1000

    AXIS2C-1596: Fix memory leaks in JSON reader
    
    Fix memory leaks in axis2_json_read_child_node for json_type_null handling:
    
    1. Fix error path: When axiom_attribute_create fails, free namespace (ns)
       instead of trying to free the NULL attribute
    
    2. After axiom_element_add_attribute succeeds:
       - Release attribute reference (element increments refcount)
       - Free original namespace (element clones via declare_namespace)
    
    These fixes eliminate 237 bytes leaked in 10 allocations detected by ASAN.
    
    Co-Authored-By: Claude Opus 4.5 <no...@anthropic.com>
---
 src/core/transport/http/util/axis2_json_reader.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/core/transport/http/util/axis2_json_reader.c b/src/core/transport/http/util/axis2_json_reader.c
index e9194bb0e..c6ba28d04 100644
--- a/src/core/transport/http/util/axis2_json_reader.c
+++ b/src/core/transport/http/util/axis2_json_reader.c
@@ -165,7 +165,7 @@ axis2_json_read_child_node(
         attr = axiom_attribute_create(env, "nil", "true", ns);
         if (!attr)
         {
-            axiom_attribute_free(attr, env);
+            axiom_namespace_free(ns, env);
             return AXIS2_FAILURE;
         }
 
@@ -176,7 +176,11 @@ axis2_json_read_child_node(
             return AXIS2_FAILURE;
         }
 
-        /* Free the namespace after successful use */
+        /* AXIS2C-1596: Release resources after adding attribute to element.
+         * axiom_element_add_attribute:
+         * - Declares/clones the namespace in the element (so we free original ns)
+         * - Increments attribute refcount (so we release our reference) */
+        axiom_attribute_free(attr, env);
         axiom_namespace_free(ns, env);
 
         break;