Author: kaushalye
Date: Wed Nov 28 04:12:37 2007
New Revision: 598978

URL: http://svn.apache.org/viewvc?rev=598978&view=rev
Log:
memory leak fixes

Modified:
    webservices/rampart/trunk/c/samples/authn_provider/authn_provider.c
    webservices/rampart/trunk/c/src/omxmlsec/axiom.c
    webservices/rampart/trunk/c/src/util/rampart_context.c
    webservices/rampart/trunk/c/src/util/rampart_encryption.c
    webservices/rampart/trunk/c/src/util/rampart_sec_header_builder.c
    webservices/rampart/trunk/c/src/util/rampart_signature.c
    webservices/rampart/trunk/c/src/util/rampart_username_token.c

Modified: webservices/rampart/trunk/c/samples/authn_provider/authn_provider.c
URL: 
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/samples/authn_provider/authn_provider.c?rev=598978&r1=598977&r2=598978&view=diff
==============================================================================
--- webservices/rampart/trunk/c/samples/authn_provider/authn_provider.c 
(original)
+++ webservices/rampart/trunk/c/samples/authn_provider/authn_provider.c Wed Nov 
28 04:12:37 2007
@@ -168,11 +168,11 @@
 axis2_remove_instance(rampart_authn_provider_t *inst,
         const axutil_env_t *env)
 {
-    axis2_status_t status = AXIS2_FAILURE;
     if (inst)
     {
-        status = AXIS2_SVC_SKELETON_FREE(inst, env);
+        AXIS2_FREE(env->allocator, inst->ops);
+               AXIS2_FREE(env->allocator, inst);
     }
-    return status;
+    return AXIS2_SUCCESS;
 }
 

Modified: webservices/rampart/trunk/c/src/omxmlsec/axiom.c
URL: 
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/axiom.c?rev=598978&r1=598977&r2=598978&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/axiom.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/axiom.c Wed Nov 28 04:12:37 2007
@@ -49,8 +49,11 @@
 
     ele =  axiom_node_get_data_element(node, env);
     attr =  axiom_attribute_create(env, attribute , value, ns);
+       if(!attr && ns)
+       {
+               axiom_namespace_free(ns, env);
+       }
     status = axiom_element_add_attribute(ele, env, attr, node);
-
     return status;
 }
 

Modified: webservices/rampart/trunk/c/src/util/rampart_context.c
URL: 
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/util/rampart_context.c?rev=598978&r1=598977&r2=598978&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/util/rampart_context.c (original)
+++ webservices/rampart/trunk/c/src/util/rampart_context.c Wed Nov 28 04:12:37 
2007
@@ -230,16 +230,17 @@
         {
             axutil_param_t *param = NULL;
             param = rampart_context->authn_provider->param;
+                       /*User specific free logic*/
+            RAMPART_AUTHN_PROVIDER_FREE(rampart_context->authn_provider, env);
+            rampart_context->authn_provider = NULL;
             if(param){
                 /*We actually free the dll_desc, which is set as the value of 
the axutil parameter.*/
-                axutil_dll_desc_t *dll_desc_l = NULL;
+                               axutil_param_free(param, env);
+                /*axutil_dll_desc_t *dll_desc_l = NULL;
                 dll_desc_l = axutil_param_get_value(param, env);
                 status = axutil_class_loader_delete_dll(env, dll_desc_l);
-                dll_desc_l = NULL;
+                dll_desc_l = NULL;*/
             }
-            /*User specific free logic*/
-            /*RAMPART_AUTHN_PROVIDER_FREE(rampart_context->authn_provider, 
env);*/
-            rampart_context->authn_provider = NULL;
         }
 
         if(rampart_context->session_key)

Modified: webservices/rampart/trunk/c/src/util/rampart_encryption.c
URL: 
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/util/rampart_encryption.c?rev=598978&r1=598977&r2=598978&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/util/rampart_encryption.c (original)
+++ webservices/rampart/trunk/c/src/util/rampart_encryption.c Wed Nov 28 
04:12:37 2007
@@ -222,10 +222,12 @@
     axutil_array_list_t *dk_list = NULL;
     axis2_char_t *enc_sym_algo = NULL;
     axis2_char_t *asym_key_id = NULL;
+       axis2_bool_t free_asym_key_id = AXIS2_FALSE;
     axiom_node_t *encrypted_key_node = NULL;
     axiom_node_t *sig_node = NULL;
     axiom_node_t *data_ref_list_node = NULL;
     axis2_bool_t use_derived_keys = AXIS2_TRUE;
+       axis2_bool_t free_session_key = AXIS2_FALSE;
     axis2_bool_t server_side = AXIS2_FALSE;
     rp_property_t *token = NULL;
     axis2_bool_t signature_protection = AXIS2_FALSE;
@@ -283,6 +285,7 @@
         session_key = oxs_key_create(env);
         status = oxs_key_for_algo(session_key, env, enc_sym_algo);
         rampart_context_set_session_key(rampart_context, env, session_key);
+               free_session_key = AXIS2_TRUE;
     }
  
     id_list = axutil_array_list_create(env, 5);
@@ -352,6 +355,20 @@
             {
                 AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                                 "[rampart][rampart_encryption] Cannot encrypt 
the node " );
+                               if(free_session_key)
+                               {
+                                       oxs_key_free(session_key, env);
+                                       session_key = NULL;
+                               }
+                               for(j=0 ; j < axutil_array_list_size(id_list, 
env); j++)
+                               {
+                                       axis2_char_t *id = NULL;
+                                       id = (axis2_char_t 
*)axutil_array_list_get(id_list, env, j);
+                                       AXIS2_FREE(env->allocator, id);
+                               }
+                               axutil_array_list_free(id_list, env);
+                               id_list = NULL; 
+
                 return AXIS2_FAILURE;
             }
 
@@ -376,6 +393,19 @@
         if(AXIS2_FAILURE == status){
             AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                                 "[rampart][rampart_encryption] Cannot encrypt 
the session key " );
+                       if(free_session_key)
+                       {
+                               oxs_key_free(session_key, env);
+                               session_key = NULL;
+                       }
+                       for(j=0 ; j < axutil_array_list_size(id_list, env); j++)
+                       {
+                               axis2_char_t *id = NULL;
+                               id = (axis2_char_t 
*)axutil_array_list_get(id_list, env, j);
+                               AXIS2_FREE(env->allocator, id);
+                       }
+                       axutil_array_list_free(id_list, env);
+                       id_list = NULL;
             return AXIS2_FAILURE;
         }
         /*Now we have en EncryptedKey Node*/
@@ -386,9 +416,23 @@
         {
             AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                         "[rampart][rampart_encryption]Encrypting signature, 
EncryptedKey Not found");
+                       if(free_session_key)
+                       {
+                               oxs_key_free(session_key, env);
+                               session_key = NULL;
+                       }
+                       for(j=0 ; j < axutil_array_list_size(id_list, env); j++)
+                       {
+                               axis2_char_t *id = NULL;
+                               id = (axis2_char_t 
*)axutil_array_list_get(id_list, env, j);
+                               AXIS2_FREE(env->allocator, id);
+                       }
+                       axutil_array_list_free(id_list, env);
+                       id_list = NULL;
             return AXIS2_FAILURE;
         }
         asym_key_id = oxs_util_generate_id(env, (axis2_char_t*)OXS_ENCKEY_ID);
+               free_asym_key_id = AXIS2_TRUE;
         if(asym_key_id)
         {
             oxs_axiom_add_attribute(env, encrypted_key_node, NULL,
@@ -424,9 +468,26 @@
     dk_list = NULL;
 
     /*Free derrived Id list*/
+       for(j=0 ; j < axutil_array_list_size(id_list, env); j++)
+       {
+               axis2_char_t *id = NULL;
+               id = (axis2_char_t *)axutil_array_list_get(id_list, env, j);
+               AXIS2_FREE(env->allocator, id);
+       }
     axutil_array_list_free(id_list, env);
     id_list = NULL; 
     
+       if(free_session_key && session_key)
+       {
+               oxs_key_free(session_key, env);
+               session_key = NULL;
+       }
+
+       if(free_asym_key_id && asym_key_id)
+       {
+               AXIS2_FREE(env->allocator, asym_key_id);
+       }
+
     return status;
 }
 

Modified: webservices/rampart/trunk/c/src/util/rampart_sec_header_builder.c
URL: 
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/util/rampart_sec_header_builder.c?rev=598978&r1=598977&r2=598978&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/util/rampart_sec_header_builder.c (original)
+++ webservices/rampart/trunk/c/src/util/rampart_sec_header_builder.c Wed Nov 
28 04:12:37 2007
@@ -326,6 +326,7 @@
         tmp_node = axiom_node_detach(dk_node, env);
         axiom_node_insert_sibling_after(enc_key_node, env, tmp_node);
     }
+       axutil_array_list_free(dk_list, env);
     return AXIS2_SUCCESS;
 }
 

Modified: webservices/rampart/trunk/c/src/util/rampart_signature.c
URL: 
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/util/rampart_signature.c?rev=598978&r1=598977&r2=598978&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/util/rampart_signature.c (original)
+++ webservices/rampart/trunk/c/src/util/rampart_signature.c Wed Nov 28 
04:12:37 2007
@@ -246,6 +246,7 @@
     rp_property_t *token = NULL;
     axis2_bool_t use_derived_keys = AXIS2_FALSE;
     axis2_bool_t server_side = AXIS2_FALSE;
+       axis2_bool_t free_session_key = AXIS2_FALSE;
  
     /*We are trying to reuse the same session key which is used for 
encryption*/
     session_key = rampart_context_get_session_key(rampart_context, env);
@@ -254,6 +255,7 @@
         session_key = oxs_key_create(env);
         oxs_key_for_algo(session_key, env, OXS_HREF_HMAC_SHA1);
         rampart_context_set_session_key(rampart_context, env, session_key);
+               free_session_key = AXIS2_TRUE;
     }
     /*If we need to use derrived keys, we must sign using a derived key of the 
session key*/
     server_side = axis2_msg_ctx_get_server_side(msg_ctx, env);
@@ -274,6 +276,10 @@
     oxs_sign_ctx_set_c14n_mtd(sign_ctx, env, OXS_HREF_XML_EXC_C14N);
     oxs_sign_ctx_set_operation(sign_ctx, env, OXS_SIGN_OPERATION_SIGN);
     
+       if(free_session_key)
+       {
+               oxs_key_free(session_key, env);
+       }
     return AXIS2_SUCCESS;
 }
 
@@ -668,6 +674,7 @@
         oxs_key_t *signed_key = NULL;
         oxs_key_t *session_key = NULL;
         axis2_char_t *enc_key_id = NULL;
+               axis2_bool_t free_enc_key_id = AXIS2_FALSE;
 
         signed_key = oxs_sign_ctx_get_secret(sign_ctx, env);    
         session_key = rampart_context_get_session_key(rampart_context, env);
@@ -684,6 +691,7 @@
             encrypted_key_node = oxs_axiom_get_node_by_local_name(env, 
sec_node,  OXS_NODE_ENCRYPTED_KEY);
             /*Add Id attribute*/
             enc_key_id = oxs_util_generate_id(env, 
(axis2_char_t*)OXS_ENCKEY_ID);
+                       free_enc_key_id = AXIS2_TRUE;
             oxs_axiom_add_attribute(env, encrypted_key_node, NULL, NULL, 
OXS_ATTR_ID, enc_key_id);
             /*And we have to make sure that we place this newly generated 
EncryptedKey node above the Signature node*/
             oxs_axiom_interchange_nodes(env, encrypted_key_node, sig_node);
@@ -706,6 +714,10 @@
             /*We need to make DerivedKeyToken to appear before the sginature 
node*/
             oxs_axiom_interchange_nodes(env, dk_token, sig_node);
         }
+               if (free_enc_key_id)
+               {
+                       AXIS2_FREE(env->allocator, enc_key_id);
+               }
     }
 
     /*If we have used derived keys, then we need to free the key in sign_ctx*/

Modified: webservices/rampart/trunk/c/src/util/rampart_username_token.c
URL: 
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/util/rampart_username_token.c?rev=598978&r1=598977&r2=598978&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/util/rampart_username_token.c (original)
+++ webservices/rampart/trunk/c/src/util/rampart_username_token.c Wed Nov 28 
04:12:37 2007
@@ -230,6 +230,7 @@
     rampart_authn_provider_t *authn_provider = NULL;
     axis2_char_t *password_from_svr = NULL;
     axis2_char_t *password_to_compare = NULL;
+       axis2_bool_t free_password_to_compare = AXIS2_FALSE;
     axis2_ctx_t *ctx = NULL;
     rampart_authn_provider_status_t auth_status= 
RAMPART_AUTHN_PROVIDER_GENERAL_ERROR ;
     axiom_element_t *ut_ele = NULL;
@@ -541,6 +542,7 @@
                                   created, password_from_svr);
             rampart_set_security_processed_result(env, msg_ctx,
                                                   
RAMPART_SPR_UT_PASSWORD_TYPE, RAMPART_PASSWORD_DIGEST_URI);
+                       free_password_to_compare = AXIS2_TRUE;
         }
         else
         {
@@ -556,6 +558,10 @@
                            "[rampart][rampart_usernametoken] Password 
comparison SUCCESS");
             rampart_set_security_processed_result(env, msg_ctx,
                                                   RAMPART_SPR_UT_CHECKED, 
RAMPART_YES);
+                       if(free_password_to_compare)
+                       {
+                               AXIS2_FREE(env->allocator, password_to_compare);
+                       }
             return AXIS2_SUCCESS;
         }
         else
@@ -563,6 +569,10 @@
             AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                             "[rampart][rampart_usernametoken] Password is not 
valid for user %s",
                             username);
+                       if(free_password_to_compare)
+                       {
+                               AXIS2_FREE(env->allocator, password_to_compare);
+                       }
             return AXIS2_FAILURE;
         }
     }


Reply via email to