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/17 18:38:46 UTC

(axis-axis2-c-core) 02/04: Fix double-free and crash during svc_client cleanup (AXIS2C-1632)

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 c2b2c8b861b4bfc872e161b4c3393f378be5cc55
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Sat Jan 17 07:34:26 2026 -1000

    Fix double-free and crash during svc_client cleanup (AXIS2C-1632)
    
    After commit 8f7b38a58 added automatic key cleanup to axutil_hash_free(),
    several places still had manual key-freeing loops that now cause double-frees:
    
    1. axis2_svc_free() in svc.c: Removed manual key freeing loop for
       op_action_map since hash_free now handles this automatically.
    
    2. axis2_core_utils_free_rest_map() in core_utils.c: Removed manual key
       freeing since hash_free handles it.
    
    3. axis2_libcurl.c: Removed custom free_func (libcurl_stream_free) for
       the AXIS2_TRANSPORT_IN property. This function pointer becomes invalid
       when the libcurl library is unloaded during conf_ctx_free(), causing
       a crash when options_free() tries to call it. The default property
       cleanup (AXIS2_FREE) correctly handles the stream struct.
    
    Verified with valgrind: 0 memory errors after fix (was 12+ errors before).
    
    Co-Authored-By: Claude Opus 4.5 <no...@anthropic.com>
---
 src/core/description/svc.c                             | 15 ++-------------
 src/core/transport/http/sender/libcurl/axis2_libcurl.c |  6 ++++--
 src/core/util/core_utils.c                             | 11 +++--------
 3 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/src/core/description/svc.c b/src/core/description/svc.c
index c1ce0d44e..e379ca272 100644
--- a/src/core/description/svc.c
+++ b/src/core/description/svc.c
@@ -406,19 +406,8 @@ axis2_svc_free(
 
     if(svc->op_action_map)
     {
-        axutil_hash_index_t *hi = NULL;
-        const void *key = NULL;
-
-        for(hi = axutil_hash_first(svc->op_action_map, env); hi; hi = axutil_hash_next(env, hi))
-        {
-            axutil_hash_this(hi, &key, NULL, NULL);
-
-            if(key)
-            {
-                AXIS2_FREE(env->allocator, (axis2_char_t *)key);
-                key = NULL;
-            }
-        }
+        /* AXIS2C-1632: Keys are now freed by axutil_hash_free when key_is_copy is set.
+         * Do not manually free keys here to avoid double-free. */
         axutil_hash_free(svc->op_action_map, env);
     }
 
diff --git a/src/core/transport/http/sender/libcurl/axis2_libcurl.c b/src/core/transport/http/sender/libcurl/axis2_libcurl.c
index e85e988cb..c14a359e2 100644
--- a/src/core/transport/http/sender/libcurl/axis2_libcurl.c
+++ b/src/core/transport/http/sender/libcurl/axis2_libcurl.c
@@ -566,8 +566,10 @@ axis2_libcurl_send(
     in_stream = axutil_stream_create_libcurl(env, data->memory, data->size);
     trans_in_property = axutil_property_create(env);
     axutil_property_set_scope(trans_in_property, env, AXIS2_SCOPE_REQUEST);
-    axutil_property_set_free_func(trans_in_property, env,
-        libcurl_stream_free);
+    /* Do not set a custom free_func pointing to libcurl_stream_free.
+     * The libcurl library may be unloaded before the property is freed,
+     * making the function pointer invalid. The default property cleanup
+     * (AXIS2_FREE when own_value is true) correctly frees the stream struct. */
     axutil_property_set_value(trans_in_property, env, in_stream);
     axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_TRANSPORT_IN,
         trans_in_property);
diff --git a/src/core/util/core_utils.c b/src/core/util/core_utils.c
index f5153d886..ff60c6d5a 100644
--- a/src/core/util/core_utils.c
+++ b/src/core/util/core_utils.c
@@ -728,13 +728,12 @@ axis2_core_utils_free_rest_map(
 {
 
     axutil_hash_index_t *hi = NULL;
-    const void *key = NULL;
     void *val = NULL;
     axis2_status_t status = AXIS2_SUCCESS;
 
     for(hi = axutil_hash_first(rest_map, env); hi; hi = axutil_hash_next(env, hi))
     {
-        axutil_hash_this(hi, &key, NULL, &val);
+        axutil_hash_this(hi, NULL, NULL, &val);
 
         if(val)
         {
@@ -753,12 +752,8 @@ axis2_core_utils_free_rest_map(
             }
             AXIS2_FREE(env->allocator, mapping_struct);
         }
-
-        if(key)
-        {
-            AXIS2_FREE(env->allocator, (axis2_char_t *)key);
-            key = NULL;
-        }
+        /* AXIS2C-1632: Keys are now freed by axutil_hash_free when key_is_copy is set.
+         * Do not manually free keys here to avoid double-free. */
     }
     axutil_hash_free(rest_map, env);
     return status;