Memory leak fixes.
authorPekka Riikonen <priikone@silcnet.org>
Fri, 16 Feb 2007 20:06:06 +0000 (20:06 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 16 Feb 2007 20:06:06 +0000 (20:06 +0000)
lib/silcasn1/silcasn1_encode.c
lib/silcclient/client.c
lib/silcclient/client_channel.c
lib/silcclient/command_reply.c
lib/silccrypt/silcpk.c

index f4937390e76de8fd575eb91d133ae20550cc1370..63b455cc2b82010368d03abdbeb057879b5dd143 100644 (file)
@@ -21,6 +21,8 @@
 #include "silcasn1.h"
 #include "silcber.h"
 
+#define SILC_ASN1_BUFFER_FREE(b, stack) if (!stack) silc_buffer_purge(b);
+
 /************************** ASN.1 Encoder routines **************************/
 
 /* Encode string from UTF-8 string to other string encodings.  Encodes
@@ -136,10 +138,10 @@ silc_asn1_encoder(SilcAsn1 asn1, SilcStack stack1, SilcStack stack2,
       ret = silc_asn1_encoder(asn1, stack2, stack1, type, type,
                              SILC_BER_CLASS_UNIVERSAL, opts,
                              &buf, depth + 1, primitive);
-      silc_stack_pop(stack2);
 
       if (!ret) {
        SILC_LOG_DEBUG(("Error encoding explicit tag"));
+       silc_stack_pop(stack2);
        goto fail;
       }
 
@@ -149,6 +151,8 @@ silc_asn1_encoder(SilcAsn1 asn1, SilcStack stack1, SilcStack stack2,
                                       silc_buffer_truelen(dest) + len);
       ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_CONSTRUCTED,
                            tag, buf.data, silc_buffer_len(&buf), FALSE);
+      SILC_ASN1_BUFFER_FREE(&buf, stack2);
+      silc_stack_pop(stack2);
       if (!ret)
        goto fail;
       if (primitive) {
@@ -237,9 +241,9 @@ silc_asn1_encoder(SilcAsn1 asn1, SilcStack stack1, SilcStack stack2,
        silc_stack_push(stack2, &frame);
        ret = silc_asn1_encoder(asn1, stack2, stack1, rtype, rtag, rclass,
                                ropts, &buf, depth + 1, FALSE);
-       silc_stack_pop(stack2);
        if (!ret) {
          SILC_LOG_DEBUG(("Error traversing a SEQUENCE/SET"));
+         silc_stack_pop(stack2);
          goto fail;
        }
 
@@ -249,6 +253,8 @@ silc_asn1_encoder(SilcAsn1 asn1, SilcStack stack1, SilcStack stack2,
                                         silc_buffer_truelen(dest) + len);
        ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_CONSTRUCTED,
                              tag, buf.data, silc_buffer_len(&buf), indef);
+       SILC_ASN1_BUFFER_FREE(&buf, stack2);
+       silc_stack_pop(stack2);
        if (!ret)
          goto fail;
        break;
@@ -286,6 +292,7 @@ silc_asn1_encoder(SilcAsn1 asn1, SilcStack stack1, SilcStack stack2,
                                         silc_buffer_truelen(dest) + len);
        ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_PRIMITIVE,
                              tag, buf.data, silc_buffer_len(&buf), FALSE);
+       SILC_ASN1_BUFFER_FREE(&buf, stack2);
        silc_stack_pop(stack2);
        if (!ret)
          goto fail;
@@ -324,6 +331,7 @@ silc_asn1_encoder(SilcAsn1 asn1, SilcStack stack1, SilcStack stack2,
                                         silc_buffer_truelen(dest) + len);
        ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_PRIMITIVE,
                              tag, buf.data, silc_buffer_len(&buf), FALSE);
+       SILC_ASN1_BUFFER_FREE(&buf, stack2);
        silc_stack_pop(stack2);
        if (!ret)
          goto fail;
@@ -414,6 +422,7 @@ silc_asn1_encoder(SilcAsn1 asn1, SilcStack stack1, SilcStack stack2,
                                         silc_buffer_truelen(dest) + len);
        ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_PRIMITIVE,
                              tag, buf.data, silc_buffer_len(&buf), FALSE);
+       SILC_ASN1_BUFFER_FREE(&buf, stack2);
        silc_stack_pop(stack2);
        if (!ret)
          goto fail;
@@ -463,6 +472,7 @@ silc_asn1_encoder(SilcAsn1 asn1, SilcStack stack1, SilcStack stack2,
                                         silc_buffer_truelen(dest) + len);
        ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_PRIMITIVE,
                              tag, buf.data, silc_buffer_len(&buf), indef);
+       SILC_ASN1_BUFFER_FREE(&buf, stack2);
        silc_stack_pop(stack2);
        if (!ret)
          goto fail;
index 5eeb6c3505d697a9c49215d4131d33d4528ef69c..1d7884553696564c1dd8bca8477034cfc25760ce 100644 (file)
@@ -730,10 +730,9 @@ void silc_client_del_connection(SilcClient client, SilcClientConnection conn)
   if (conn->internal->sha1hash)
     silc_hash_free(conn->internal->sha1hash);
   silc_atomic_uninit16(&conn->internal->cmd_ident);
-
+  silc_free(conn->internal->away_message);
   if (conn->internal->rekey)
     silc_ske_free_rekey_material(conn->internal->rekey);
-
   if (conn->internal->cop)
     silc_async_free(conn->internal->cop);
 
index 554864320ddc24c53f1e3199218c6aed2a488d83..7143c0e721aa734819971dac404aec36d3b514c9 100644 (file)
@@ -469,6 +469,7 @@ SilcBool silc_client_save_channel_key(SilcClient client,
   silc_hmac_set_key(channel->internal.hmac, hash,
                    silc_hash_len(silc_hmac_get_hash(channel->internal.hmac)));
   memset(hash, 0, sizeof(hash));
+  silc_channel_key_payload_free(payload);
 
   silc_client_unref_channel(client, conn, channel);
 
index 8317c61717481920e8c03e7c857dcddf1f45812d..a4b9959202498134165c77fd56dcea423bd5e325 100644 (file)
@@ -514,7 +514,7 @@ SILC_FSM_STATE(silc_client_command_reply_whois)
 
   silc_client_unref_client(client, conn, client_entry);
   if (has_channels) {
-    silc_dlist_uninit(channel_list);
+    silc_channel_payload_list_free(channel_list);
     silc_free(umodes);
   }
 
index e012e3709732aed9e9eaf7f6d2c1efe3ddf98931..9075c8aa7a66fc47466d4115db982e5ce307e0a9 100644 (file)
@@ -677,6 +677,7 @@ unsigned char *silc_pkcs_silc_export_public_key(void *public_key,
   silc_buffer_free(buf);
   silc_free(key);
   silc_free(identifier);
+  silc_buffer_purge(&alg_key);
   silc_asn1_free(asn1);
 
   return ret;
@@ -1529,6 +1530,7 @@ unsigned char *silc_pkcs_silc_export_private_key(void *private_key,
   silc_buffer_free(buf);
   silc_free(prv);
   silc_free(key);
+  silc_buffer_purge(&alg_key);
   silc_asn1_free(asn1);
 
   return ret;