[gnome-keyring/trust-store: 5/7] [gcr] Fix memory leaks in certificate chain code.



commit 42f78db0c04f11e8603ad979955403beae50af27
Author: Stef Walter <stefw collabora co uk>
Date:   Mon Dec 13 19:37:19 2010 +0000

    [gcr] Fix memory leaks in certificate chain code.

 gcr/gcr-certificate-chain.c        |   10 ++++++----
 gcr/tests/test-certificate-chain.c |    5 ++++-
 2 files changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/gcr/gcr-certificate-chain.c b/gcr/gcr-certificate-chain.c
index de57532..934559f 100644
--- a/gcr/gcr-certificate-chain.c
+++ b/gcr/gcr-certificate-chain.c
@@ -192,11 +192,11 @@ prep_chain_private_thread_safe (GcrCertificateChainPrivate *orig, const gchar *p
 			der = gcr_certificate_get_der_data (certificate, &n_der);
 			g_return_val_if_fail (der, NULL);
 			safe = gcr_simple_certificate_new (der, n_der);
-		}
 
-		/* Always set the original certificate onto the safe one */
-		g_object_set_qdata_full (G_OBJECT (safe), Q_ORIGINAL_CERT,
-		                         g_object_ref (certificate), g_object_unref);
+			/* Always set the original certificate onto the safe one */
+			g_object_set_qdata_full (G_OBJECT (safe), Q_ORIGINAL_CERT,
+			                         g_object_ref (certificate), g_object_unref);
+		}
 
 		g_ptr_array_index (pv->certificates, i) = safe;
 		g_object_unref (certificate);
@@ -669,6 +669,8 @@ gcr_certificate_chain_build (GcrCertificateChain *self, const gchar *purpose,
 		self->pv = cleanup_chain_private (pv);
 		g_object_notify (G_OBJECT (self), "status");
 		g_object_notify (G_OBJECT (self), "length");
+	} else {
+		free_chain_private (pv);
 	}
 
 	return ret;
diff --git a/gcr/tests/test-certificate-chain.c b/gcr/tests/test-certificate-chain.c
index 0556a8a..8a3856a 100644
--- a/gcr/tests/test-certificate-chain.c
+++ b/gcr/tests/test-certificate-chain.c
@@ -214,7 +214,7 @@ TESTING_TEARDOWN (certificate_chain)
 	cert_signed = NULL;
 
 	g_object_unref (cert_ca);
-	cert_signed = NULL;
+	cert_ca = NULL;
 
 	rv = (funcs.C_Finalize) (NULL);
 	gck_assert_cmprv (rv, ==, CKR_OK);
@@ -521,6 +521,7 @@ TESTING_TEST (certificate_chain_with_lookup_error)
 	                                 NULL, 0, NULL, &error))
 		g_assert_not_reached ();
 	g_assert_error (error, GCK_ERROR, CKR_FUNCTION_FAILED);
+	g_clear_error (&error);
 
 	g_assert_cmpuint (gcr_certificate_chain_get_status (chain), ==,
 	                  GCR_CERTIFICATE_CHAIN_UNKNOWN);
@@ -546,6 +547,7 @@ TESTING_TEST (certificate_chain_with_anchor_error)
 	                                 NULL, 0, NULL, &error))
 		g_assert_not_reached ();
 	g_assert_error (error, GCK_ERROR, CKR_FUNCTION_FAILED);
+	g_clear_error (&error);
 
 	g_assert_cmpuint (gcr_certificate_chain_get_status (chain), ==,
 	                  GCR_CERTIFICATE_CHAIN_UNKNOWN);
@@ -574,6 +576,7 @@ TESTING_TEST (certificate_chain_with_anchor_error_async)
 	if (gcr_certificate_chain_build_finish (chain, result, &error))
 		g_assert_not_reached ();
 	g_assert_error (error, GCK_ERROR, CKR_FUNCTION_FAILED);
+	g_clear_error (&error);
 	g_object_unref (result);
 
 	g_assert_cmpuint (gcr_certificate_chain_get_status (chain), ==,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]