Author: damitha
Date: Tue May  6 11:36:01 2008
New Revision: 653876

URL: http://svn.apache.org/viewvc?rev=653876&view=rev
Log:
Fixing memory leaks.

Modified:
    webservices/sandesha/trunk/c/config/module.xml
    webservices/sandesha/trunk/c/samples/rm_ping_1_0/rm_ping_1_0.c
    webservices/sandesha/trunk/c/src/msgprocessors/app_msg_processor.c
    webservices/sandesha/trunk/c/src/storage/sqlite/permanent_storage_mgr.c
    webservices/sandesha/trunk/c/src/workers/sender_worker.c

Modified: webservices/sandesha/trunk/c/config/module.xml
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/config/module.xml?rev=653876&r1=653875&r2=653876&view=diff
==============================================================================
--- webservices/sandesha/trunk/c/config/module.xml (original)
+++ webservices/sandesha/trunk/c/config/module.xml Tue May  6 11:36:01 2008
@@ -82,6 +82,6 @@
     <parameter name="SenderSleepTime" locked="false">100000</parameter><!--In 
micro seconds-->
     <parameter name="InvokerSleepTime" locked="false">1</parameter>
     <parameter name="PollingWaitTime" locked="false">2</parameter>
-    <parameter name="TerminateDelay" locked="false">2</parameter>
+    <parameter name="TerminateDelay" locked="false">4</parameter>
 
 </module>

Modified: webservices/sandesha/trunk/c/samples/rm_ping_1_0/rm_ping_1_0.c
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/samples/rm_ping_1_0/rm_ping_1_0.c?rev=653876&r1=653875&r2=653876&view=diff
==============================================================================
--- webservices/sandesha/trunk/c/samples/rm_ping_1_0/rm_ping_1_0.c (original)
+++ webservices/sandesha/trunk/c/samples/rm_ping_1_0/rm_ping_1_0.c Tue May  6 
11:36:01 2008
@@ -23,7 +23,7 @@
 #include <sandesha2_constants.h>
 #include <ctype.h>
 
-#define SANDESHA2_SLEEP 12
+#define SANDESHA2_SLEEP 5
 
 axiom_node_t *
 build_om_programatically(
@@ -140,14 +140,14 @@
     if(status)
         printf("\nping client invoke SUCCESSFUL!\n");
     payload = NULL;
-    /*AXIS2_SLEEP(SANDESHA2_SLEEP);*/
+    AXIS2_SLEEP(SANDESHA2_SLEEP);
     
     payload = build_om_programatically(env, "ping2", seq_key);
     status = axis2_svc_client_send_robust(svc_client, env, payload);
     if(status)
         printf("\nping client invoke SUCCESSFUL!\n");
     payload = NULL;
-    /*AXIS2_SLEEP(SANDESHA2_SLEEP);*/
+    AXIS2_SLEEP(SANDESHA2_SLEEP);
 
     property = axutil_property_create_with_args(env, 0, 0, 0, 
AXIS2_VALUE_TRUE);
     axis2_options_set_property(options, env, "Sandesha2LastMessage", 

Modified: webservices/sandesha/trunk/c/src/msgprocessors/app_msg_processor.c
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/src/msgprocessors/app_msg_processor.c?rev=653876&r1=653875&r2=653876&view=diff
==============================================================================
--- webservices/sandesha/trunk/c/src/msgprocessors/app_msg_processor.c 
(original)
+++ webservices/sandesha/trunk/c/src/msgprocessors/app_msg_processor.c Tue May  
6 11:36:01 2008
@@ -261,7 +261,7 @@
     }
     
     op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
-    axis2_op_ctx_set_in_use(op_ctx, env, AXIS2_TRUE);
+    /*axis2_op_ctx_set_in_use(op_ctx, env, AXIS2_TRUE);*/
     axis2_op_ctx_set_response_written(op_ctx, env, AXIS2_TRUE);
     conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
     dbname = sandesha2_util_get_dbname(env, conf_ctx);
@@ -1208,22 +1208,20 @@
         }
         else
         {
-            {
-                axutil_property_t *property = NULL;
-                axis2_ctx_t *ctx = axis2_conf_ctx_get_base(conf_ctx, env);
-                axutil_hash_t *msg_ctx_map = NULL;
+            axutil_property_t *property = NULL;
+            axis2_ctx_t *ctx = axis2_conf_ctx_get_base(conf_ctx, env);
+            axutil_hash_t *msg_ctx_map = NULL;
 
-                property = axis2_ctx_get_property(ctx, env, 
SANDESHA2_MSG_CTX_MAP);
-                if(!property)
-                {
-                    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
-                        "[sandesha2]msg_ctx_map not found in the conf_ctx");
-                    msg_ctx_map = axutil_hash_make(env);
-                    property = axutil_property_create_with_args(env, 
AXIS2_SCOPE_APPLICATION,
-                        AXIS2_TRUE, axutil_hash_free_void_arg, msg_ctx_map);
-                    axis2_ctx_set_property(ctx, env, SANDESHA2_MSG_CTX_MAP,
-                        property);
-                }
+            property = axis2_ctx_get_property(ctx, env, SANDESHA2_MSG_CTX_MAP);
+            if(!property)
+            {
+                AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
+                    "[sandesha2]msg_ctx_map not found in the conf_ctx");
+                msg_ctx_map = axutil_hash_make(env);
+                property = axutil_property_create_with_args(env, 
AXIS2_SCOPE_APPLICATION,
+                    AXIS2_TRUE, axutil_hash_free_void_arg, msg_ctx_map);
+                axis2_ctx_set_property(ctx, env, SANDESHA2_MSG_CTX_MAP,
+                    property);
             }
             AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Starting the client "\
                 "sequence with internal sequence id %s", internal_seq_id);
@@ -1544,7 +1542,6 @@
     axis2_engine_t *engine = NULL;
     axutil_property_t *property = NULL;
     axis2_char_t *msg_id = NULL;
-    axis2_op_ctx_t *temp_opctx = NULL;   
 
     AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,   
         "[Sandesha2]Entry:sandesha2_app_msg_processor_add_create_seq_msg");
@@ -1602,8 +1599,6 @@
         create_seq_msg, env), NULL);
     sandesha2_create_seq_bean_set_ref_msg_store_key(create_seq_bean, env, 
         str_key);
-    temp_opctx = axis2_msg_ctx_get_op_ctx(create_seq_msg, env);
-    /*axis2_op_ctx_increment_ref(temp_opctx, env);*/
     sandesha2_create_seq_mgr_insert(create_seq_mgr, env, create_seq_bean);
     addr_ns_uri = sandesha2_utils_get_seq_property(env, internal_seq_id, 
         SANDESHA2_SEQ_PROP_ADDRESSING_NAMESPACE_VALUE, seq_prop_mgr);
@@ -1697,7 +1692,9 @@
     axis2_bool_t last_msg = AXIS2_FALSE;
     axis2_op_ctx_t *temp_op_ctx = NULL;
     axis2_status_t status = AXIS2_FAILURE;
-    
+    int mep = -1;
+    axis2_conf_ctx_t *conf_ctx = NULL;
+
     AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,   
         "[Sandesha2] sandesha2_app_msg_processor_process_response_msg");
     AXIS2_PARAM_CHECK(env->error, internal_seq_id, AXIS2_FAILURE);
@@ -1707,6 +1704,7 @@
     AXIS2_PARAM_CHECK(env->error, sender_mgr, AXIS2_FAILURE);
     
     app_msg_ctx = sandesha2_msg_ctx_get_msg_ctx(rm_msg_ctx, env);
+    conf_ctx = axis2_msg_ctx_get_conf_ctx(app_msg_ctx, env);
     to_bean = sandesha2_seq_property_mgr_retrieve(seq_prop_mgr, env, 
         internal_seq_id, SANDESHA2_SEQ_PROP_TO_EPR);
     reply_to_bean = sandesha2_seq_property_mgr_retrieve(seq_prop_mgr, env, 
@@ -1884,8 +1882,7 @@
             seq_prop_mgr);
         if(req_rm_msg_ctx)
             sandesha2_msg_ctx_free(req_rm_msg_ctx, env);
-        engine = axis2_engine_create(env, axis2_msg_ctx_get_conf_ctx(msg_ctx, 
-            env));
+        engine = axis2_engine_create(env, conf_ctx);
         return axis2_engine_resume_send(engine, env, msg_ctx);
     }
     if(rm_version)
@@ -1913,10 +1910,37 @@
            SANDESHA2_SET_SEND_TO_TRUE, property);
     }
     temp_op_ctx = axis2_msg_ctx_get_op_ctx(app_msg_ctx, env);
-    axis2_op_ctx_increment_ref(temp_op_ctx, env);
+    /**
+     * In RM one way out only(from client application side) we need to keep the
+     * operation context of the application message context marked as in-use.
+     * Otherwise when client send the next application message and free the
+     * previous op_client this op_ctx is freed.
+     */
+    mep = axis2_op_get_axis_specific_mep_const(axis2_op_ctx_get_op(temp_op_ctx,
+        env), env);
+    if(AXIS2_MEP_CONSTANT_OUT_ONLY == mep)
+    {
+        axis2_ctx_t *ctx = axis2_conf_ctx_get_base(conf_ctx, env);
+        axutil_property_t *temp_prop =
+            axis2_ctx_get_property(ctx, env, SANDESHA2_MSG_CTX_MAP);
+        if(temp_prop)
+        {
+            axis2_op_ctx_set_in_use(temp_op_ctx, env, AXIS2_TRUE);
+        }
+    }
+
     property = axutil_property_create_with_args(env, 0, 0, 0, 
AXIS2_VALUE_FALSE);
     axis2_msg_ctx_set_property(app_msg_ctx, env, 
         SANDESHA2_QUALIFIED_FOR_SENDING, property);
+    /**
+     * When we store application message context as below it should be noted
+     * that at Sandesha2/C client application side this is actually stored in
+     * in-memory whereas in the web service side it is actually stored in
+     * database only. In RM one way scenario since we call
+     * axis2_op_ctx_set_in_use() for the operation context of the application
+     * message in few lines above we need to free that operation context in the
+     * sandesha2_storage_mgr_remove_msg_ctx() function.
+     */
     sandesha2_storage_mgr_store_msg_ctx(storage_mgr, env, storage_key, 
app_msg_ctx);
     sandesha2_sender_mgr_insert(sender_mgr, env, app_msg_entry);
     
@@ -1940,8 +1964,7 @@
     }
     axis2_msg_ctx_set_current_handler_index(app_msg_ctx, env, 
         axis2_msg_ctx_get_current_handler_index(app_msg_ctx, env) + 1);
-    engine = axis2_engine_create(env, axis2_msg_ctx_get_conf_ctx(app_msg_ctx, 
-        env));
+    engine = axis2_engine_create(env, conf_ctx);
     status = axis2_engine_resume_send(engine, env, app_msg_ctx);
     if(engine)
         axis2_engine_free(engine, env);

Modified: 
webservices/sandesha/trunk/c/src/storage/sqlite/permanent_storage_mgr.c
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/src/storage/sqlite/permanent_storage_mgr.c?rev=653876&r1=653875&r2=653876&view=diff
==============================================================================
--- webservices/sandesha/trunk/c/src/storage/sqlite/permanent_storage_mgr.c 
(original)
+++ webservices/sandesha/trunk/c/src/storage/sqlite/permanent_storage_mgr.c Tue 
May  6 11:36:01 2008
@@ -242,30 +242,27 @@
     axis2_char_t *key,
     axis2_msg_ctx_t *msg_ctx)
 {
+    axis2_conf_ctx_t *conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
+    axutil_property_t *property = NULL;
+    axis2_ctx_t *ctx = axis2_conf_ctx_get_base(conf_ctx, env);
     sandesha2_msg_store_bean_t *msg_store_bean = NULL;
     sandesha2_permanent_storage_mgr_t *storage_mgr_impl = NULL;
     storage_mgr_impl = SANDESHA2_INTF_TO_IMPL(storage_mgr);
-    {
-        axis2_conf_ctx_t *conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
-        axutil_property_t *property = NULL;
-        axis2_ctx_t *ctx = axis2_conf_ctx_get_base(conf_ctx, env);
-        axutil_hash_t *msg_ctx_map = NULL;
-
-        property = axis2_ctx_get_property(ctx, env, SANDESHA2_MSG_CTX_MAP);
-        if(property)
-        {
-            msg_ctx_map = axutil_property_get_value(property, env);
-
-            axutil_hash_set(msg_ctx_map, axutil_strdup(env, key), 
-                AXIS2_HASH_KEY_STRING, msg_ctx);
-        }
-    }
+    
+    property = axis2_ctx_get_property(ctx, env, SANDESHA2_MSG_CTX_MAP);
     axis2_msg_ctx_set_keep_alive(msg_ctx, env, AXIS2_TRUE);
     msg_store_bean = sandesha2_permanent_storage_mgr_get_msg_store_bean(
         storage_mgr, env, msg_ctx);
     sandesha2_msg_store_bean_set_stored_key(msg_store_bean, env, key);
     
sandesha2_permanent_bean_mgr_insert_msg_store_bean(storage_mgr_impl->bean_mgr, 
         env, msg_store_bean);
+    if(property)
+    {
+        axutil_hash_t *msg_ctx_map = NULL;
+        msg_ctx_map = axutil_property_get_value(property, env);
+        axutil_hash_set(msg_ctx_map, axutil_strdup(env, key),
+            AXIS2_HASH_KEY_STRING, msg_ctx);
+    }
     if(msg_store_bean)
         sandesha2_msg_store_bean_free(msg_store_bean, env);
     return AXIS2_SUCCESS;
@@ -349,18 +346,18 @@
                         axis2_msg_ctx_get_op_ctx(msg_ctx, env);
                     if(msg_type == SANDESHA2_MSG_TYPE_APPLICATION)
                     {
-                        axiom_soap_envelope_t *soap_envelope = 
+                        /*axiom_soap_envelope_t *soap_envelope = 
                             axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
                         axis2_op_ctx_set_in_use(op_ctx, env, AXIS2_FALSE);
                         axiom_soap_envelope_free(soap_envelope, env);
-                        axis2_op_ctx_free(op_ctx, env);
+                        axis2_op_ctx_free(op_ctx, env);*/
                         axutil_hash_set(msg_ctx_map, key, 
AXIS2_HASH_KEY_STRING, 
                             NULL);
                         AXIS2_FREE(env->allocator, key_l);
                     }
                     else if(msg_type != SANDESHA2_MSG_TYPE_CREATE_SEQ)
                     {
-                        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+                        /*AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
                             "[sandesha2]Removing msg_ctx with msg_id:%s", 
                             axis2_msg_ctx_get_msg_id(msg_ctx, env));
                         axis2_op_ctx_set_in_use(op_ctx, env, AXIS2_FALSE);
@@ -369,7 +366,7 @@
                         axis2_op_ctx_free(op_ctx, env);
                         axutil_hash_set(msg_ctx_map, key, 
AXIS2_HASH_KEY_STRING, 
                             NULL);
-                        AXIS2_FREE(env->allocator, key_l);
+                        AXIS2_FREE(env->allocator, key_l);*/
                     }
                 }
             }

Modified: webservices/sandesha/trunk/c/src/workers/sender_worker.c
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/src/workers/sender_worker.c?rev=653876&r1=653875&r2=653876&view=diff
==============================================================================
--- webservices/sandesha/trunk/c/src/workers/sender_worker.c (original)
+++ webservices/sandesha/trunk/c/src/workers/sender_worker.c Tue May  6 
11:36:01 2008
@@ -358,10 +358,8 @@
     {
         AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
             "[sandesha2]message of msg_type:%d successfully sent", msg_type);
-        if(AXIS2_FALSE == axis2_msg_ctx_get_server_side(msg_ctx, env) ||
-            msg_type == SANDESHA2_MSG_TYPE_ACK)
-            sandesha2_sender_worker_check_for_sync_res(env, msg_ctx, 
-                storage_mgr, msg_type);
+        sandesha2_sender_worker_check_for_sync_res(env, msg_ctx, 
+            storage_mgr, msg_type);
     }
     if(SANDESHA2_MSG_TYPE_TERMINATE_SEQ == msg_type)
     {
@@ -403,17 +401,6 @@
     if(bean1)
         sandesha2_sender_bean_free(bean1, env);
 
-    /*if(msg_ctx && msg_type != SANDESHA2_MSG_TYPE_APPLICATION && 
-        msg_type != SANDESHA2_MSG_TYPE_CREATE_SEQ)
-    {
-        axis2_op_ctx_t *op_ctx = NULL;
-        op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
-        if(op_ctx)
-            axis2_op_ctx_free(op_ctx, env);
-        axis2_msg_ctx_set_keep_alive(msg_ctx, env, AXIS2_FALSE);
-        axis2_msg_ctx_set_paused(msg_ctx, env, AXIS2_FALSE);
-        axis2_msg_ctx_free(msg_ctx, env);
-    }*/
     if(rm_msg_ctx)
         sandesha2_msg_ctx_free(rm_msg_ctx, env);
     AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, 
@@ -464,12 +451,13 @@
     axis2_op_t *op = NULL;
     axis2_conf_ctx_t *conf_ctx = NULL;
     axis2_conf_t *conf = NULL;
-    axis2_bool_t free_msg = AXIS2_FALSE;
+    axis2_bool_t svr_side = AXIS2_FALSE;
    
     AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
         "[sandesha2]Entry:sandesha2_sender_worker_check_for_sync_res");
     AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
-
+    
+    svr_side = axis2_msg_ctx_get_server_side(msg_ctx, env);
     if(!msg_ctx)
         return AXIS2_SUCCESS;
     soap_ns_uri = axis2_msg_ctx_get_is_soap_11(msg_ctx, env) ?
@@ -477,8 +465,14 @@
          AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI;
 
     res_envelope = axis2_msg_ctx_get_response_soap_envelope(msg_ctx, env);
-    if(res_envelope && msg_type == SANDESHA2_MSG_TYPE_APPLICATION)
+    if(res_envelope && msg_type == SANDESHA2_MSG_TYPE_APPLICATION && !svr_side)
     {
+        /* When service client is freed by the application client operation
+         * context and hence msg_ctx and therefore soap envelope is freed.
+         * To avoid that we increment the soap envelope. This soap envelope
+         * will be freed when we free the application op_ctx below.
+         */
+
         axiom_soap_envelope_increment_ref(res_envelope, env);
         /* To avoid a second passing through incoming handlers at op_client*/
         property = axutil_property_create_with_args(env, 0, 0, 0, 
@@ -492,12 +486,31 @@
             "[sandesha2]Response envelope not found");
         res_envelope = axis2_http_transport_utils_create_soap_msg(env, msg_ctx,
             soap_ns_uri);
-        free_msg = AXIS2_TRUE;
         if(!res_envelope)
         {
+            if(msg_type == SANDESHA2_MSG_TYPE_CREATE_SEQ || msg_type ==
+                SANDESHA2_MSG_TYPE_TERMINATE_SEQ || msg_type ==
+                SANDESHA2_MSG_TYPE_ACK)
+            {
+                /* These are Sandesha2/C created messages. Also because there 
is 
+                 * no response for these messages we can deduce that they are
+                 * one way messages. So this is the only place we can free the
+                 * corresponding operation context.
+                 */
+                axis2_op_ctx_t *op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx,
+                    env);
+                axis2_op_ctx_free(op_ctx, env);
+            }
             return AXIS2_SUCCESS;
         }
     }
+    if(svr_side)
+    {
+        /* We check and process the sync response only in the application 
client 
+         * side.
+         */
+        return AXIS2_SUCCESS;
+    }
     conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
     conf = axis2_conf_ctx_get_conf(conf_ctx, env);
     svc_grp = axis2_msg_ctx_get_svc_grp(msg_ctx, env);
@@ -617,11 +630,15 @@
         if(engine)
             axis2_engine_free(engine, env);
     }
-    if(free_msg)
+    if(msg_type == SANDESHA2_MSG_TYPE_CREATE_SEQ || msg_type ==
+        SANDESHA2_MSG_TYPE_TERMINATE_SEQ || msg_type == SANDESHA2_MSG_TYPE_ACK)
     {
-        axiom_soap_envelope_free(res_envelope, env);
+        axis2_op_ctx_t *op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx,
+            env);
+        axis2_op_ctx_free(op_ctx, env);
     }
-    if(msg_type == SANDESHA2_MSG_TYPE_CREATE_SEQ)
+    if(msg_type == SANDESHA2_MSG_TYPE_CREATE_SEQ || msg_type == 
+            SANDESHA2_MSG_TYPE_APPLICATION)
     {
         axis2_op_ctx_t *op_ctx = axis2_msg_ctx_get_op_ctx(res_msg_ctx, env);
         axis2_op_ctx_free(op_ctx, env);



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to