You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2006/11/14 16:19:35 UTC

svn commit: r474815 - in /webservices/axis2/trunk/c: modules/core/clientapi/ modules/core/context/ modules/core/receivers/ modules/core/transport/http/ samples/client/echo/

Author: samisa
Date: Tue Nov 14 07:19:34 2006
New Revision: 474815

URL: http://svn.apache.org/viewvc?view=rev&rev=474815
Log:
Fixed loads of memory leaks

Modified:
    webservices/axis2/trunk/c/modules/core/clientapi/callback_recv.c
    webservices/axis2/trunk/c/modules/core/clientapi/op_client.c
    webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c
    webservices/axis2/trunk/c/modules/core/context/ctx.c
    webservices/axis2/trunk/c/modules/core/context/msg_ctx.c
    webservices/axis2/trunk/c/modules/core/context/op_ctx.c
    webservices/axis2/trunk/c/modules/core/receivers/msg_recv.c
    webservices/axis2/trunk/c/modules/core/transport/http/http_worker.c
    webservices/axis2/trunk/c/samples/client/echo/echo.c

Modified: webservices/axis2/trunk/c/modules/core/clientapi/callback_recv.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/clientapi/callback_recv.c?view=diff&rev=474815&r1=474814&r2=474815
==============================================================================
--- webservices/axis2/trunk/c/modules/core/clientapi/callback_recv.c (original)
+++ webservices/axis2/trunk/c/modules/core/clientapi/callback_recv.c Tue Nov 14 07:19:34 2006
@@ -24,6 +24,7 @@
     axis2_callback_recv_t callback_recv;
     /** base context struct */
     axis2_msg_recv_t *base;
+    axis2_bool_t base_deep_copy;
     /** callback map */
     axis2_hash_t *callback_map;
     axis2_thread_mutex_t *mutex;
@@ -77,6 +78,7 @@
 
     callback_recv_impl->callback_recv.ops = NULL;
     callback_recv_impl->base = NULL;
+    callback_recv_impl->base_deep_copy = AXIS2_TRUE;
     callback_recv_impl->callback_map = NULL;
     callback_recv_impl->mutex = NULL;
 
@@ -125,6 +127,7 @@
     const axis2_env_t *env)
 {
     AXIS2_ENV_CHECK(env, NULL);
+    AXIS2_INTF_TO_IMPL(callback_recv)->base_deep_copy = AXIS2_FALSE;
     return AXIS2_INTF_TO_IMPL(callback_recv)->base;
 }
 
@@ -166,7 +169,7 @@
         callback_recv_impl->callback_map = NULL;
     }
 
-    if (callback_recv_impl->base)
+    if (callback_recv_impl->base && callback_recv_impl->base_deep_copy)
     {
         AXIS2_MSG_RECV_FREE(callback_recv_impl->base, env);
     }

Modified: webservices/axis2/trunk/c/modules/core/clientapi/op_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/clientapi/op_client.c?view=diff&rev=474815&r1=474814&r2=474815
==============================================================================
--- webservices/axis2/trunk/c/modules/core/clientapi/op_client.c (original)
+++ webservices/axis2/trunk/c/modules/core/clientapi/op_client.c Tue Nov 14 07:19:34 2006
@@ -23,6 +23,7 @@
 #include <axis2_engine.h>
 #include "axis2_callback_recv.h"
 #include <axiom_xml_reader.h>
+#include <axis2_core_utils.h>
 
 typedef struct axis2_op_client_impl
 {
@@ -279,12 +280,13 @@
     {
         /* may be this is the second invocation using the same service clinet,
            so reset */
-        /* TODO: Fix the memory leaks here */
+        AXIS2_MSG_CTX_FREE(out_msg_ctx, env);
+        out_msg_ctx = NULL;
         axis2_hash_set(msg_ctx_map, AXIS2_WSDL_MESSAGE_LABEL_OUT_VALUE, AXIS2_HASH_KEY_STRING, NULL);
+        AXIS2_MSG_CTX_FREE(in_msg_ctx, env);
+        in_msg_ctx = NULL;
         axis2_hash_set(msg_ctx_map, AXIS2_WSDL_MESSAGE_LABEL_IN_VALUE, AXIS2_HASH_KEY_STRING, NULL);
         AXIS2_OP_CTX_SET_IS_COMPLETE(op_client_impl->op_ctx, env, AXIS2_FALSE);
-        out_msg_ctx = NULL;
-        in_msg_ctx = NULL;
     }
 
     if (!out_msg_ctx)

Modified: webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c?view=diff&rev=474815&r1=474814&r2=474815
==============================================================================
--- webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c (original)
+++ webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c Tue Nov 14 07:19:34 2006
@@ -1182,6 +1182,12 @@
 
     svc_client_impl->headers = NULL;
 
+    if (svc_client_impl->callback_recv)
+    {
+        AXIS2_CALLBACK_RECV_FREE(svc_client_impl->callback_recv, env);
+        svc_client_impl->callback_recv = NULL;
+    }
+
     svc_client_impl->callback_recv = axis2_callback_recv_create(env);
     if (!(svc_client_impl->callback_recv))
     {
@@ -1332,16 +1338,11 @@
 
     svc_client_impl = AXIS2_INTF_TO_IMPL(svc_client);
 
-    /* TODO: Fix this memory leak. 
-     *
-     * Segfault occurs with dual clients
-     *
     if (svc_client_impl->svc)
     {
         AXIS2_SVC_FREE(svc_client_impl->svc, env);
         svc_client_impl->svc = NULL;
     }
-    */
 
     if (svc_client_impl->callback_recv)
     {

Modified: webservices/axis2/trunk/c/modules/core/context/ctx.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/context/ctx.c?view=diff&rev=474815&r1=474814&r2=474815
==============================================================================
--- webservices/axis2/trunk/c/modules/core/context/ctx.c (original)
+++ webservices/axis2/trunk/c/modules/core/context/ctx.c Tue Nov 14 07:19:34 2006
@@ -24,6 +24,7 @@
     axis2_ctx_t ctx;
     /** non persistent map */
     axis2_hash_t *non_persistent_map;
+    axis2_bool_t non_persistent_map_deep_copy;
     /** persistent map */
     axis2_hash_t *persistent_map;
     /*axis2_ctx_t *parent; This will not be required as the responsibility of
@@ -109,6 +110,7 @@
     }
 
     ctx_impl->non_persistent_map = axis2_hash_make(env);
+    ctx_impl->non_persistent_map_deep_copy = AXIS2_TRUE;
     if (!(ctx_impl->non_persistent_map))
     {
         axis2_ctx_free(&(ctx_impl->ctx), env);
@@ -249,7 +251,7 @@
         ctx_impl->ctx.ops = NULL;
     }
 
-    if (ctx_impl->non_persistent_map)
+    if (ctx_impl->non_persistent_map && ctx_impl->non_persistent_map_deep_copy)
     {
         axis2_hash_index_t *hi = NULL;
         void *val = NULL;
@@ -319,7 +321,7 @@
 
     ctx_impl = AXIS2_INTF_TO_IMPL(ctx);
 
-    if (ctx_impl->non_persistent_map)
+    if (ctx_impl->non_persistent_map && ctx_impl->non_persistent_map_deep_copy)
     {
         axis2_hash_index_t *hi = NULL;
         void *val = NULL;
@@ -349,6 +351,7 @@
     }
 
     ctx_impl->non_persistent_map = map;
+    ctx_impl->non_persistent_map_deep_copy = AXIS2_FALSE;
 
     return AXIS2_SUCCESS;
 }

Modified: webservices/axis2/trunk/c/modules/core/context/msg_ctx.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/context/msg_ctx.c?view=diff&rev=474815&r1=474814&r2=474815
==============================================================================
--- webservices/axis2/trunk/c/modules/core/context/msg_ctx.c (original)
+++ webservices/axis2/trunk/c/modules/core/context/msg_ctx.c Tue Nov 14 07:19:34 2006
@@ -49,6 +49,7 @@
      * information is present in the SOAP header.
      */
     axis2_msg_info_headers_t *msg_info_headers;
+    axis2_bool_t msg_info_headers_deep_copy;
 
     struct axis2_op_ctx *op_ctx;
     struct axis2_svc_ctx *svc_ctx;
@@ -750,6 +751,7 @@
         axis2_msg_ctx_free(&(msg_ctx_impl->msg_ctx), env);
         return NULL;
     }
+    msg_ctx_impl->msg_info_headers_deep_copy = AXIS2_TRUE;
 
     /* initialize ops */
     msg_ctx_impl->msg_ctx.ops  = AXIS2_MALLOC(env->allocator, sizeof(axis2_msg_ctx_ops_t));
@@ -929,7 +931,7 @@
         msg_ctx_impl->base = NULL;
     }
 
-    if (msg_ctx_impl->msg_info_headers)
+    if (msg_ctx_impl->msg_info_headers && msg_ctx_impl->msg_info_headers_deep_copy)
     {
         AXIS2_MSG_INFO_HEADERS_FREE(msg_ctx_impl->msg_info_headers, env);
         msg_ctx_impl->msg_info_headers = NULL;
@@ -1825,13 +1827,15 @@
 
     if (msg_info_headers)
     {
-        if (AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers)
+        if (AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers && 
+            AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers_deep_copy)
         {
             AXIS2_MSG_INFO_HEADERS_FREE(
                 AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers, env);
             AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers = NULL;
         }
         AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers = msg_info_headers;
+        AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers_deep_copy = AXIS2_FALSE;
     }
 
     return AXIS2_SUCCESS;
@@ -2475,8 +2479,16 @@
 
     msg_ctx_impl = AXIS2_INTF_TO_IMPL(msg_ctx);
 
+    if (AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers && msg_ctx_impl->msg_info_headers_deep_copy)
+    {
+        AXIS2_MSG_INFO_HEADERS_FREE(
+            AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers, env);
+        AXIS2_INTF_TO_IMPL(msg_ctx)->msg_info_headers = NULL;
+    }
     msg_ctx_impl->msg_info_headers =
         AXIS2_OPTIONS_GET_MSG_INFO_HEADERS(options, env);
+    msg_ctx_impl->msg_info_headers_deep_copy = AXIS2_FALSE;
+
     AXIS2_CTX_SET_NON_PERSISTANT_MAP(msg_ctx_impl->base, env,
             AXIS2_OPTIONS_GET_PROPERTIES(options, env));
     rest_val = (axis2_char_t *)AXIS2_MSG_CTX_GET_PROPERTY(msg_ctx, env,

Modified: webservices/axis2/trunk/c/modules/core/context/op_ctx.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/context/op_ctx.c?view=diff&rev=474815&r1=474814&r2=474815
==============================================================================
--- webservices/axis2/trunk/c/modules/core/context/op_ctx.c (original)
+++ webservices/axis2/trunk/c/modules/core/context/op_ctx.c Tue Nov 14 07:19:34 2006
@@ -261,9 +261,23 @@
 
     if (op_ctx_impl->msg_ctx_map)
     {
+        axis2_hash_index_t *hi = NULL;
+        void *ctx = NULL;
+        for (hi = axis2_hash_first(op_ctx_impl->msg_ctx_map, env);
+            hi; hi = axis2_hash_next(env, hi))
+        {
+            axis2_hash_this(hi, NULL, NULL, &ctx);
+            if (ctx)
+            {
+                axis2_msg_ctx_t *msg_ctx = (axis2_msg_ctx_t*)ctx;
+                AXIS2_MSG_CTX_FREE(msg_ctx, env);
+            }
+        }
+
         axis2_hash_free(op_ctx_impl->msg_ctx_map, env);
         op_ctx_impl->msg_ctx_map = NULL;
     }
+
     if (op_ctx_impl->mutex)
     {
         axis2_thread_mutex_destroy(op_ctx_impl->mutex);

Modified: webservices/axis2/trunk/c/modules/core/receivers/msg_recv.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/receivers/msg_recv.c?view=diff&rev=474815&r1=474814&r2=474815
==============================================================================
--- webservices/axis2/trunk/c/modules/core/receivers/msg_recv.c (original)
+++ webservices/axis2/trunk/c/modules/core/receivers/msg_recv.c Tue Nov 14 07:19:34 2006
@@ -482,7 +482,9 @@
     {
         axis2_core_utils_reset_out_msg_ctx(env, out_msg_ctx);
     }
-    AXIS2_MSG_CTX_FREE(out_msg_ctx, env);
+    /* this is freed in http worker by resetting the operation context 
+       holding this msg context
+    AXIS2_MSG_CTX_FREE(out_msg_ctx, env); */
     out_msg_ctx = NULL;
     return status;
 }

Modified: webservices/axis2/trunk/c/modules/core/transport/http/http_worker.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/transport/http/http_worker.c?view=diff&rev=474815&r1=474814&r2=474815
==============================================================================
--- webservices/axis2/trunk/c/modules/core/transport/http/http_worker.c (original)
+++ webservices/axis2/trunk/c/modules/core/transport/http/http_worker.c Tue Nov 14 07:19:34 2006
@@ -425,7 +425,37 @@
     status = AXIS2_SIMPLE_HTTP_SVR_CONN_WRITE_RESPONSE(svr_conn, env, response);
     AXIS2_FREE(env->allocator, url_external_form);
     url_external_form = NULL;
-    AXIS2_MSG_CTX_FREE(msg_ctx, env);
+    /* this is freed in the following block of logic, taking it from 
+       operation context that holds it
+    AXIS2_MSG_CTX_FREE(msg_ctx, env); */
+    /* Free message contextx */
+    if (op_ctx) 
+    {
+        axis2_msg_ctx_t *out_msg_ctx = NULL, *in_msg_ctx = NULL;
+        axis2_hash_t *msg_ctx_map = NULL;
+
+        msg_ctx_map = AXIS2_OP_CTX_GET_MSG_CTX_MAP(op_ctx, env);
+
+        out_msg_ctx = axis2_hash_get(msg_ctx_map, AXIS2_WSDL_MESSAGE_LABEL_OUT_VALUE,
+                AXIS2_HASH_KEY_STRING);
+        in_msg_ctx = axis2_hash_get(msg_ctx_map, AXIS2_WSDL_MESSAGE_LABEL_IN_VALUE,
+                AXIS2_HASH_KEY_STRING);
+
+        if (out_msg_ctx)
+        {
+            AXIS2_MSG_CTX_FREE(out_msg_ctx, env);
+            out_msg_ctx = NULL;
+            axis2_hash_set(msg_ctx_map, AXIS2_WSDL_MESSAGE_LABEL_OUT_VALUE, AXIS2_HASH_KEY_STRING, NULL);
+        }
+
+        if (in_msg_ctx)
+        {
+            AXIS2_MSG_CTX_FREE(in_msg_ctx, env);
+            in_msg_ctx = NULL;
+            axis2_hash_set(msg_ctx_map, AXIS2_WSDL_MESSAGE_LABEL_IN_VALUE, AXIS2_HASH_KEY_STRING, NULL);
+        }
+    } /* Done freeing message contexts */
+    
     msg_ctx = NULL;
     AXIS2_URL_FREE(request_url, env);
     request_url = NULL;

Modified: webservices/axis2/trunk/c/samples/client/echo/echo.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/client/echo/echo.c?view=diff&rev=474815&r1=474814&r2=474815
==============================================================================
--- webservices/axis2/trunk/c/samples/client/echo/echo.c (original)
+++ webservices/axis2/trunk/c/samples/client/echo/echo.c Tue Nov 14 07:19:34 2006
@@ -34,6 +34,8 @@
     axis2_svc_client_t* svc_client = NULL;
     axiom_node_t *payload = NULL;
     axiom_node_t *ret_node = NULL;
+    axiom_node_t *payload2 = NULL;
+    axiom_node_t *ret_node2 = NULL;
     /*axis2_allocator_t *allocator = NULL;*/
 
     /* Set up the environment */
@@ -94,6 +96,8 @@
     /* Send request */
     ret_node = AXIS2_SVC_CLIENT_SEND_RECEIVE(svc_client, env, payload);
 
+    payload2 = build_om_payload_for_echo_svc(env);
+    ret_node2 = AXIS2_SVC_CLIENT_SEND_RECEIVE(svc_client, env, payload2);
     if (ret_node)
     {
         axis2_char_t *om_str = NULL;
@@ -113,11 +117,11 @@
         printf("echo client invoke FAILED!\n");
     }
 
-    if (payload)
+    /*if (payload)
     {
         AXIOM_NODE_FREE_TREE(payload, env);
         payload = NULL;
-    }
+    }*/
 
     if (svc_client)
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org