[glib-networking] gnutls: fix a few memory leaks
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking] gnutls: fix a few memory leaks
- Date: Sat, 17 Sep 2011 16:23:08 +0000 (UTC)
commit 6a9957e216e2edd26bc8ca0c88dda642fa30e21d
Author: Dan Winship <danw gnome org>
Date: Sat Sep 17 12:22:25 2011 -0400
gnutls: fix a few memory leaks
tls/gnutls/gtlsconnection-gnutls.c | 2 ++
tls/gnutls/gtlsdatabase-gnutls.c | 1 +
tls/gnutls/gtlsfiledatabase-gnutls.c | 8 +++++---
tls/gnutls/gtlsinputstream-gnutls.c | 3 +++
tls/gnutls/gtlsoutputstream-gnutls.c | 3 +++
tls/tests/tls.c | 23 ++++++++++++++++++++++-
6 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index 0f792bb..c698521 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -1025,6 +1025,8 @@ g_tls_connection_gnutls_handshake_async (GTlsConnection *conn,
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
}
+ else if (error)
+ g_error_free (error);
source = g_tls_connection_gnutls_create_source (gnutls, 0, cancellable);
g_source_set_callback (source,
diff --git a/tls/gnutls/gtlsdatabase-gnutls.c b/tls/gnutls/gtlsdatabase-gnutls.c
index ed82435..18d46fa 100644
--- a/tls/gnutls/gtlsdatabase-gnutls.c
+++ b/tls/gnutls/gtlsdatabase-gnutls.c
@@ -130,6 +130,7 @@ build_certificate_chain (GTlsDatabaseGnutls *self,
return STATUS_INCOMPLETE;
g_return_val_if_fail (G_IS_TLS_CERTIFICATE_GNUTLS (issuer), STATUS_FAILURE);
g_tls_certificate_gnutls_set_issuer (certificate, G_TLS_CERTIFICATE_GNUTLS (issuer));
+ g_object_unref (issuer);
}
g_assert (issuer);
diff --git a/tls/gnutls/gtlsfiledatabase-gnutls.c b/tls/gnutls/gtlsfiledatabase-gnutls.c
index c215dd5..f393be5 100644
--- a/tls/gnutls/gtlsfiledatabase-gnutls.c
+++ b/tls/gnutls/gtlsfiledatabase-gnutls.c
@@ -228,8 +228,7 @@ load_anchor_file (const gchar *filename,
if (*error)
return FALSE;
-
- for (l = list; l; l = g_list_next (l))
+ for (l = list; l; l = l->next)
{
cert = g_tls_certificate_gnutls_get_cert (l->data);
gerr = gnutls_x509_crt_get_raw_dn (cert, &dn);
@@ -271,7 +270,10 @@ load_anchor_file (const gchar *filename,
g_byte_array_unref (der);
g_byte_array_unref (subject);
g_byte_array_unref (issuer);
+
+ g_object_unref (l->data);
}
+ g_list_free (list);
return TRUE;
}
@@ -560,7 +562,7 @@ g_tls_file_database_gnutls_lookup_certificates_issued_by (GTlsDatabase
{
if (g_cancellable_set_error_if_cancelled (cancellable, error))
{
- for (l = issued; l != NULL; l = g_list_next (l))
+ for (l = issued; l != NULL; l = l->next)
g_object_unref (l->data);
g_list_free (issued);
issued = NULL;
diff --git a/tls/gnutls/gtlsinputstream-gnutls.c b/tls/gnutls/gtlsinputstream-gnutls.c
index 6970883..a89ac50 100644
--- a/tls/gnutls/gtlsinputstream-gnutls.c
+++ b/tls/gnutls/gtlsinputstream-gnutls.c
@@ -146,6 +146,9 @@ g_tls_input_stream_gnutls_read_async (GInputStream *stream,
return;
}
+ if (error)
+ g_error_free (error);
+
tls_stream->priv->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
tls_stream->priv->buffer = buffer;
tls_stream->priv->count = count;
diff --git a/tls/gnutls/gtlsoutputstream-gnutls.c b/tls/gnutls/gtlsoutputstream-gnutls.c
index 2e101e4..178835e 100644
--- a/tls/gnutls/gtlsoutputstream-gnutls.c
+++ b/tls/gnutls/gtlsoutputstream-gnutls.c
@@ -146,6 +146,9 @@ g_tls_output_stream_gnutls_write_async (GOutputStream *stream,
return;
}
+ if (error)
+ g_error_free (error);
+
tls_stream->priv->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
tls_stream->priv->buffer = buffer;
tls_stream->priv->count = count;
diff --git a/tls/tests/tls.c b/tls/tests/tls.c
index 1feae68..58664b7 100644
--- a/tls/tests/tls.c
+++ b/tls/tests/tls.c
@@ -71,7 +71,16 @@ static void
teardown_connection (TestConnection *test, gconstpointer data)
{
if (test->service)
- g_object_unref (test->service);
+ {
+ g_socket_service_stop (test->service);
+ /* The outstanding accept_async will hold a ref on test->service,
+ * which we want to wait for it to release if we're valgrinding.
+ */
+ g_object_add_weak_pointer (G_OBJECT (test->service), (gpointer *)&test->service);
+ g_object_unref (test->service);
+ while (test->service)
+ g_main_context_iteration (NULL, TRUE);
+ }
if (test->server_connection)
{
@@ -316,6 +325,7 @@ test_verified_connection (TestConnection *test,
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
g_assert (test->client_connection);
+ g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
@@ -346,6 +356,7 @@ test_client_auth_connection (TestConnection *test,
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
g_assert (test->client_connection);
+ g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
@@ -384,6 +395,7 @@ test_connection_no_database (TestConnection *test,
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
g_assert (test->client_connection);
+ g_object_unref (connection);
/* Overrides loading of the default database */
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), NULL);
@@ -581,6 +593,11 @@ teardown_verify (TestVerify *test,
(gpointer *)&test->database);
g_object_unref (test->database);
g_assert (test->database == NULL);
+
+ g_object_add_weak_pointer (G_OBJECT (test->identity),
+ (gpointer *)&test->identity);
+ g_object_unref (test->identity);
+ g_assert (test->identity == NULL);
}
static void
@@ -1054,5 +1071,9 @@ main (int argc,
ret = g_test_run();
g_free (source_dir);
+
+ /* for valgrinding */
+ g_main_context_unref (g_main_context_default ());
+
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]