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/13 22:20:51 UTC

(axis-axis2-c-core) 05/06: AXIS2C-1542: Fix qname memory leaks in generated stub code

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 4a9b04ae54a7e09c870566a6a351d3cde12c1e93
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Tue Jan 13 11:47:56 2026 -1000

    AXIS2C-1542: Fix qname memory leaks in generated stub code
    
    The generated stub code was leaking axutil_qname_t objects in the
    service population function:
    
    1. Service qname was created inline and never freed
    2. Operation qnames were created but never freed after use
    
    Both axis2_svc_create_with_qname() and axis2_op_create_with_qname()
    copy the qname rather than taking ownership, so the caller must free
    the qname after the call.
    
    Fix: Create qnames as variables and free them immediately after use.
    
    Co-Authored-By: Claude Opus 4.5 <no...@anthropic.com>
---
 tools/codegen/native/src/stub_generator.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/codegen/native/src/stub_generator.c b/tools/codegen/native/src/stub_generator.c
index b77c0234f..1b75efcf8 100644
--- a/tools/codegen/native/src/stub_generator.c
+++ b/tools/codegen/native/src/stub_generator.c
@@ -598,11 +598,14 @@ generate_stub_source(wsdl2c_context_t *context, const axutil_env_t *env)
     fprintf(source_file, "        axis2_stub_populate_services_for_%s(axis2_stub_t *stub, const axutil_env_t *env)\n", service_name);
     fprintf(source_file, "        {\n");
     fprintf(source_file, "            axis2_svc_t *svc = NULL;\n");
+    fprintf(source_file, "            axutil_qname_t *svc_qname = NULL;\n");
     fprintf(source_file, "            axutil_qname_t *op_qname = NULL;\n");
     fprintf(source_file, "            axis2_op_t *op = NULL;\n");
     fprintf(source_file, "            \n");
-    fprintf(source_file, "            /* Create service */\n");
-    fprintf(source_file, "            svc = axis2_svc_create_with_qname(env, axutil_qname_create(env, \"%s\", \"http://localhost/axis/%s\", NULL));\n", service_name, service_name);
+    fprintf(source_file, "            /* AXIS2C-1542: Create service qname and free after use to prevent leak */\n");
+    fprintf(source_file, "            svc_qname = axutil_qname_create(env, \"%s\", \"http://localhost/axis/%s\", NULL);\n", service_name, service_name);
+    fprintf(source_file, "            svc = axis2_svc_create_with_qname(env, svc_qname);\n");
+    fprintf(source_file, "            axutil_qname_free(svc_qname, env);\n");
     fprintf(source_file, "            \n");
 
     /* Add operations - generated from parsed WSDL */
@@ -616,6 +619,7 @@ generate_stub_source(wsdl2c_context_t *context, const axutil_env_t *env)
                 fprintf(source_file, "            op_qname = axutil_qname_create(env, \"%s\", \"%s\", NULL);\n",
                         op->name, context->wsdl->target_namespace ? context->wsdl->target_namespace : "");
                 fprintf(source_file, "            op = axis2_op_create_with_qname(env, op_qname);\n");
+                fprintf(source_file, "            axutil_qname_free(op_qname, env);  /* AXIS2C-1542: Free qname after use */\n");
                 fprintf(source_file, "            axis2_op_set_msg_exchange_pattern(op, env, AXIS2_MEP_URI_IN_OUT);\n");
                 fprintf(source_file, "            axis2_svc_add_op(svc, env, op);\n");
                 fprintf(source_file, "            \n");