You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2006/11/19 01:11:07 UTC

svn commit: r476664 - in /webservices/axis2/trunk/c: axiom/src/parser/libxml2/ axiom/src/soap/ modules/core/context/ modules/core/transport/http/ modules/core/transport/http/sender/ samples/client/echo/ util/src/ util/src/minizip/

Author: samisa
Date: Sat Nov 18 16:11:06 2006
New Revision: 476664

URL: http://svn.apache.org/viewvc?view=rev&rev=476664
Log:
Fixed multiple memory leaks.

Modified:
    webservices/axis2/trunk/c/axiom/src/parser/libxml2/libxml2_reader_wrapper.c
    webservices/axis2/trunk/c/axiom/src/soap/soap_builder.c
    webservices/axis2/trunk/c/modules/core/context/ctx.c
    webservices/axis2/trunk/c/modules/core/transport/http/http_transport_utils.c
    webservices/axis2/trunk/c/modules/core/transport/http/sender/soap_over_http_sender.c
    webservices/axis2/trunk/c/samples/client/echo/echo.c
    webservices/axis2/trunk/c/util/src/minizip/archive_extract.c
    webservices/axis2/trunk/c/util/src/network_handler.c

Modified: webservices/axis2/trunk/c/axiom/src/parser/libxml2/libxml2_reader_wrapper.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/parser/libxml2/libxml2_reader_wrapper.c?view=diff&rev=476664&r1=476663&r2=476664
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/parser/libxml2/libxml2_reader_wrapper.c (original)
+++ webservices/axis2/trunk/c/axiom/src/parser/libxml2/libxml2_reader_wrapper.c Sat Nov 18 16:11:06 2006
@@ -318,6 +318,7 @@
             (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler,
             (void *)env);
     wrapper_impl->current_event = -1;
+    wrapper_impl->ctx = NULL;
 
     axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
 
@@ -547,6 +548,11 @@
         const axis2_env_t *env)
 {
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    if (AXIS2_INTF_TO_IMPL(parser)->ctx)
+    {
+        AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(parser)->ctx);
+    }
+    
     if (AXIS2_INTF_TO_IMPL(parser)->reader)
     {
         xmlTextReaderClose(AXIS2_INTF_TO_IMPL(parser)->reader);

Modified: webservices/axis2/trunk/c/axiom/src/soap/soap_builder.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/soap/soap_builder.c?view=diff&rev=476664&r1=476663&r2=476664
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/soap/soap_builder.c (original)
+++ webservices/axis2/trunk/c/axiom/src/soap/soap_builder.c Sat Nov 18 16:11:06 2006
@@ -278,11 +278,13 @@
             builder_impl->builder_helper = NULL;
         }
     }
-    /*if ( builder_impl->om_builder)
+    
+    if ( builder_impl->om_builder)
     {
         AXIOM_STAX_BUILDER_FREE(builder_impl->om_builder, env);
         builder_impl->om_builder = NULL;
-    }*/
+    }
+
     if (builder->ops)
     {
         AXIS2_FREE(env->allocator, builder->ops);

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=476664&r1=476663&r2=476664
==============================================================================
--- webservices/axis2/trunk/c/modules/core/context/ctx.c (original)
+++ webservices/axis2/trunk/c/modules/core/context/ctx.c Sat Nov 18 16:11:06 2006
@@ -161,6 +161,18 @@
     }
     else
     {
+        if (value)
+        {
+            /* handle the case where we are setting a new value with the 
+               same key, we would have to free the existing value */
+            axis2_property_t *temp_value = 
+                axis2_hash_get(ctx_impl->non_persistent_map, key, 
+                    AXIS2_HASH_KEY_STRING);
+            if (temp_value && temp_value != value)
+            {
+                AXIS2_PROPERTY_FREE(temp_value, env);
+            }
+        }
         if (ctx_impl->non_persistent_map)
             axis2_hash_set(ctx_impl->non_persistent_map, key,
                     AXIS2_HASH_KEY_STRING, value);

Modified: webservices/axis2/trunk/c/modules/core/transport/http/http_transport_utils.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/transport/http/http_transport_utils.c?view=diff&rev=476664&r1=476663&r2=476664
==============================================================================
--- webservices/axis2/trunk/c/modules/core/transport/http/http_transport_utils.c (original)
+++ webservices/axis2/trunk/c/modules/core/transport/http/http_transport_utils.c Sat Nov 18 16:11:06 2006
@@ -168,7 +168,7 @@
     axis2_char_t *char_set = NULL;
     /*axis2_char_t *xml_char_set = NULL;*/
     axis2_conf_ctx_t *conf_ctx = NULL;
-    axis2_callback_info_t callback_ctx;
+    axis2_callback_info_t *callback_ctx;
     axis2_hash_t *headers = NULL;
     axis2_engine_t *engine = NULL;
     axiom_soap_body_t *soap_body = NULL;
@@ -184,11 +184,14 @@
 
     conf_ctx = AXIS2_MSG_CTX_GET_CONF_CTX(msg_ctx, env);
 
-    callback_ctx.in_stream = in_stream;
-    callback_ctx.env = env;
-    callback_ctx.content_length = content_length;
-    callback_ctx.unread_len = content_length;
-    callback_ctx.chunked_stream = NULL;
+    callback_ctx = AXIS2_MALLOC(env->allocator, sizeof(axis2_callback_info_t));
+    /* Note: the memory created above is freed in xml reader free function
+       as this is passed on to the reader */
+    callback_ctx->in_stream = in_stream;
+    callback_ctx->env = env;
+    callback_ctx->content_length = content_length;
+    callback_ctx->unread_len = content_length;
+    callback_ctx->chunked_stream = NULL;
 
     if (soap_action_header && (strlen(soap_action_header) > 0))
     {
@@ -223,9 +226,9 @@
             if (encoding_value && 0 == AXIS2_STRCASECMP(encoding_value,
                     AXIS2_HTTP_HEADER_TRANSFER_ENCODING_CHUNKED))
             {
-                callback_ctx.chunked_stream = axis2_http_chunked_stream_create(
+                callback_ctx->chunked_stream = axis2_http_chunked_stream_create(
                             env, in_stream);
-                if (NULL == callback_ctx.chunked_stream)
+                if (NULL == callback_ctx->chunked_stream)
                 {
                     AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error occured in"
                             " creating in chunked stream.");
@@ -254,8 +257,8 @@
                 and also gives out a content lenght of 0.
                 We need to fix the transport design to fix sutuations like this.
                 */
-            callback_ctx.content_length = 1000000;
-            callback_ctx.unread_len = callback_ctx.content_length;
+            callback_ctx->content_length = 1000000;
+            callback_ctx->unread_len = callback_ctx->content_length;
         }
     }
 
@@ -278,7 +281,7 @@
             {
                 binary_data_map = AXIOM_MIME_PARSER_PARSE(mime_parser, env,
                         axis2_http_transport_utils_on_data_request,
-                        (void *) & callback_ctx, mime_boundary);
+                        (void *) callback_ctx, mime_boundary);
 
                 soap_body_len = AXIOM_MIME_PARSER_GET_SOAP_BODY_LENGTH(
                             mime_parser, env);
@@ -293,10 +296,10 @@
                 AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                     "axis2_http_transport_utils_process_http_post_request soap_body_str = %s...%d soap_body_len=%d", 
                     soap_body_str, strlen(soap_body_str), soap_body_len);
-                callback_ctx.in_stream = stream;
-                callback_ctx.chunked_stream = NULL;
-                callback_ctx.content_length = soap_body_len;
-                callback_ctx.unread_len = soap_body_len;
+                callback_ctx->in_stream = stream;
+                callback_ctx->chunked_stream = NULL;
+                callback_ctx->content_length = soap_body_len;
+                callback_ctx->unread_len = soap_body_len;
             }
         }
         AXIS2_FREE(env->allocator, mime_boundary);
@@ -311,7 +314,7 @@
     char_set = axis2_http_transport_utils_get_charset_enc(env, content_type);
     xml_reader = axiom_xml_reader_create_for_io(env,
             axis2_http_transport_utils_on_data_request, NULL,
-            (void *) & callback_ctx, char_set);
+            (void *) callback_ctx, char_set);
 
     if (NULL == xml_reader)
     {
@@ -1009,8 +1012,9 @@
         in_stream = AXIS2_PROPERTY_GET_VALUE(property, env);
         property = NULL;
     }
-    /* TODO free this when xml pulling is over */
     callback_ctx = AXIS2_MALLOC(env->allocator, sizeof(axis2_callback_info_t));
+    /* Note: the memory created above is freed in xml reader free function
+       as this is passed on to the reader */
     if (NULL == callback_ctx)
     {
         AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);

Modified: webservices/axis2/trunk/c/modules/core/transport/http/sender/soap_over_http_sender.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/transport/http/sender/soap_over_http_sender.c?view=diff&rev=476664&r1=476663&r2=476664
==============================================================================
--- webservices/axis2/trunk/c/modules/core/transport/http/sender/soap_over_http_sender.c (original)
+++ webservices/axis2/trunk/c/modules/core/transport/http/sender/soap_over_http_sender.c Sat Nov 18 16:11:06 2006
@@ -368,21 +368,33 @@
     }
     else if (AXIS2_TRUE == AXIS2_MSG_CTX_GET_IS_SOAP_11(msg_ctx, env))
     {
+        axis2_char_t *temp_content_type = NULL;
         content_type = (axis2_char_t *)AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML;
         content_type = AXIS2_STRACAT(content_type, ";charset=", env);
-        content_type = AXIS2_STRACAT(content_type, char_set_enc, env);
+        temp_content_type = AXIS2_STRACAT(content_type, char_set_enc, env);
+        AXIS2_FREE(env->allocator, content_type);
+        content_type = temp_content_type;
     }
     else
     {
+        axis2_char_t *temp_content_type = NULL;
         content_type = (axis2_char_t *)AXIS2_HTTP_HEADER_ACCEPT_APPL_SOAP;
         content_type = AXIS2_STRACAT(content_type, ";charset=", env);
-        content_type = AXIS2_STRACAT(content_type, char_set_enc, env);
+        temp_content_type = AXIS2_STRACAT(content_type, char_set_enc, env);
+        AXIS2_FREE(env->allocator, content_type);
+        content_type = temp_content_type;
         if (axis2_strcmp(soap_action, ""))
         {
-            content_type = AXIS2_STRACAT(content_type, ";action=", env);
-            content_type = AXIS2_STRACAT(content_type, soap_action, env);
+            temp_content_type = AXIS2_STRACAT(content_type, ";action=", env);
+            AXIS2_FREE(env->allocator, content_type);
+            content_type = temp_content_type;
+            temp_content_type = AXIS2_STRACAT(content_type, soap_action, env);
+            AXIS2_FREE(env->allocator, content_type);
+            content_type = temp_content_type;
         }
-        content_type = AXIS2_STRACAT(content_type, ";", env);
+        temp_content_type = AXIS2_STRACAT(content_type, ";", env);
+        AXIS2_FREE(env->allocator, content_type);
+        content_type = temp_content_type;
     }
 
     http_header = axis2_http_header_create(env, AXIS2_HTTP_HEADER_CONTENT_TYPE,
@@ -759,6 +771,7 @@
         return AXIS2_FAILURE;
     }
     trans_desc = AXIS2_CONF_GET_TRANSPORT_OUT(conf, env, transport_qname);
+    AXIS2_QNAME_FREE(transport_qname, env);
     if (NULL == trans_desc)
     {
         return AXIS2_FAILURE;

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=476664&r1=476663&r2=476664
==============================================================================
--- webservices/axis2/trunk/c/samples/client/echo/echo.c (original)
+++ webservices/axis2/trunk/c/samples/client/echo/echo.c Sat Nov 18 16:11:06 2006
@@ -96,8 +96,6 @@
     /* 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;
@@ -106,7 +104,8 @@
             printf("\nReceived OM : %s\n", om_str);
         printf("\necho client invoke SUCCESSFUL!\n");
 
-        AXIOM_NODE_FREE_TREE(ret_node, env);
+        /*AXIOM_NODE_FREE_TREE(ret_node, env);*/
+        AXIS2_FREE(env->allocator, om_str);
         ret_node = NULL;
     }
     else
@@ -117,6 +116,28 @@
         printf("echo client invoke FAILED!\n");
     }
 
+    payload2 = build_om_payload_for_echo_svc(env);
+    ret_node2 = AXIS2_SVC_CLIENT_SEND_RECEIVE(svc_client, env, payload2);
+    if (ret_node2)
+    {
+        axis2_char_t *om_str = NULL;
+        om_str = AXIOM_NODE_TO_STRING(ret_node2, env);
+        if (om_str)
+            printf("\nReceived OM : %s\n", om_str);
+        printf("\necho client invoke SUCCESSFUL!\n");
+
+        /*AXIOM_NODE_FREE_TREE(ret_node2, env);*/
+        AXIS2_FREE(env->allocator, om_str);
+        ret_node2 = NULL;
+    }
+    else
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code:"
+                " %d :: %s", env->error->error_number,
+                AXIS2_ERROR_GET_MESSAGE(env->error));
+        printf("echo client invoke FAILED!\n");
+    }
+    
     /*if (payload)
     {
         AXIOM_NODE_FREE_TREE(payload, env);

Modified: webservices/axis2/trunk/c/util/src/minizip/archive_extract.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/minizip/archive_extract.c?view=diff&rev=476664&r1=476663&r2=476664
==============================================================================
--- webservices/axis2/trunk/c/util/src/minizip/archive_extract.c (original)
+++ webservices/axis2/trunk/c/util/src/minizip/archive_extract.c Sat Nov 18 16:11:06 2006
@@ -314,14 +314,25 @@
         {
             if ((strcmp(namelist[n]->d_name, ".") == 0) ||
                     (strcmp(namelist[n]->d_name, "..") == 0))
+            {
+                for (i = n; i >= 0; i--) /* clean remaining memory before return */
+                    free(namelist[i]);
+                free(namelist);
                 return (AXIS2_FALSE);
-
+            }
+            
             ptr = AXIS2_RINDEX(namelist[n]->d_name, '.');
             if ((ptr) &&
                     (((strcmp(ptr, AXIS2_AAR_SUFFIX) == 0)) || (strcmp(ptr, AXIS2_MAR_SUFFIX) == 0)))
                 for (i = 0;i < n;i++)
                     if (strncmp(namelist[n]->d_name, namelist[i]->d_name, strlen(namelist[i]->d_name)) == 0)
+                    {
+                        int j;
+                        for (j = n; j >= 0; j--) /* clean remaining memory before return */
+                            free(namelist[j]);
+                        free(namelist);
                         return (AXIS2_FALSE);
+                    }
 
             aar_extract(namelist[n]->d_name);
             free(namelist[n]);

Modified: webservices/axis2/trunk/c/util/src/network_handler.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/network_handler.c?view=diff&rev=476664&r1=476663&r2=476664
==============================================================================
--- webservices/axis2/trunk/c/util/src/network_handler.c (original)
+++ webservices/axis2/trunk/c/util/src/network_handler.c Sat Nov 18 16:11:06 2006
@@ -65,8 +65,10 @@
         lphost = gethostbyname(server); /*nnn netdb.h*/
 
         if (lphost)
+        {
             sock_addr.sin_addr.s_addr =
                 ((struct in_addr*)lphost->h_addr)->s_addr;
+        }
         else
         {
             AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS,



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