[glib-networking] tls: Fix various leaks in the TLS unit tests



commit 6d821799e6aab32563070338cd7b6aebe3ac5b25
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Mon Sep 22 09:57:22 2014 +0100

    tls: Fix various leaks in the TLS unit tests
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737106

 tls/tests/certificate.c      |    1 +
 tls/tests/connection.c       |    7 ++++++-
 tls/tests/file-database.c    |    7 ++++---
 tls/tests/mock-interaction.c |    2 ++
 4 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/tls/tests/certificate.c b/tls/tests/certificate.c
index 541d217..97c1793 100644
--- a/tls/tests/certificate.c
+++ b/tls/tests/certificate.c
@@ -295,6 +295,7 @@ test_create_list_bad (void)
   list = g_tls_certificate_list_new_from_file (tls_test_file_path ("ca-roots-bad.pem"), &error);
   g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
   g_assert_null (list);
+  g_error_free (error);
 }
 
 /* -----------------------------------------------------------------------------
diff --git a/tls/tests/connection.c b/tls/tests/connection.c
index 650ac8d..0df8bb1 100644
--- a/tls/tests/connection.c
+++ b/tls/tests/connection.c
@@ -163,6 +163,8 @@ start_server (TestConnection *test)
                                  NULL, &test->address, &error);
   g_assert_no_error (error);
 
+  g_object_unref (addr);
+
   /* The hostname in test->identity matches the server certificate. */
   iaddr = G_INET_SOCKET_ADDRESS (test->address);
   test->identity = g_network_address_new ("server.example.com",
@@ -1315,7 +1317,10 @@ async_implicit_handshake_dispatch (GPollableInputStream *stream,
   keep_running = (-1 == size);
 
   if (keep_running)
-    g_assert_error (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK);
+    {
+      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK);
+      g_error_free (error);
+    }
   else
     {
       g_assert_no_error (error);
diff --git a/tls/tests/file-database.c b/tls/tests/file-database.c
index f5107d6..1416e73 100644
--- a/tls/tests/file-database.c
+++ b/tls/tests/file-database.c
@@ -240,7 +240,7 @@ load_certificate_chain (const char  *filename,
                         GError     **error)
 {
   GList *certificates;
-  GTlsCertificate *chain = NULL;
+  GTlsCertificate *chain = NULL, *prev_chain = NULL;
   GTlsBackend *backend;
   GByteArray *der;
   GList *l;
@@ -253,12 +253,14 @@ load_certificate_chain (const char  *filename,
   certificates = g_list_reverse (certificates);
   for (l = certificates; l != NULL; l = g_list_next (l))
     {
+      prev_chain = chain;
       g_object_get (l->data, "certificate", &der, NULL);
       chain = g_object_new (g_tls_backend_get_certificate_type (backend),
                             "certificate", der,
-                            "issuer", chain,
+                            "issuer", prev_chain,
                             NULL);
       g_byte_array_unref (der);
+      g_clear_object (&prev_chain);
     }
 
   g_list_free_full (certificates, g_object_unref);
@@ -501,7 +503,6 @@ test_lookup_certificates_issued_by (void)
 
   g_list_free_full (certificates, g_object_unref);
   g_object_unref (database);
-  g_byte_array_unref (issuer_dn);
 }
 
 static void
diff --git a/tls/tests/mock-interaction.c b/tls/tests/mock-interaction.c
index 6a1d7fd..bb7502f 100644
--- a/tls/tests/mock-interaction.c
+++ b/tls/tests/mock-interaction.c
@@ -161,6 +161,8 @@ mock_interaction_finalize (GObject *object)
   MockInteraction *self = MOCK_INTERACTION (object);
 
   g_free (self->static_password);
+  g_clear_object (&self->static_certificate);
+  g_clear_error (&self->static_error);
 
   G_OBJECT_CLASS (mock_interaction_parent_class)->finalize (object);
 }


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