[libsoup] Fix memory leaks, update libsoup.supp



commit 5613f4c7ef6450b700c60be48972a5c150272e74
Author: Dan Winship <danw gnome org>
Date:   Mon Mar 28 14:59:00 2011 -0400

    Fix memory leaks, update libsoup.supp

 libsoup/soup-auth-basic.c   |    4 ++
 libsoup/soup-message.c      |    3 ++
 libsoup/soup-server.c       |   33 ++++++++++++------
 libsoup/soup-session-sync.c |    2 +
 libsoup/soup-session.c      |    1 -
 libsoup/soup-socket.c       |    3 ++
 tests/auth-test.c           |    6 ++-
 tests/libsoup.supp          |   76 +++++++++++++++++++++++++++++++++++--------
 tests/proxy-test.c          |    7 ++--
 9 files changed, 103 insertions(+), 32 deletions(-)
---
diff --git a/libsoup/soup-auth-basic.c b/libsoup/soup-auth-basic.c
index cf8bf47..4218f7e 100644
--- a/libsoup/soup-auth-basic.c
+++ b/libsoup/soup-auth-basic.c
@@ -109,6 +109,10 @@ authenticate (SoupAuth *auth, const char *username, const char *password)
 	user_pass = g_strdup_printf ("%s:%s", username, password);
 	len = strlen (user_pass);
 
+	if (priv->token) {
+		memset (priv->token, 0, strlen (priv->token));
+		g_free (priv->token);
+	}
 	priv->token = g_base64_encode ((guchar *)user_pass, len);
 
 	memset (user_pass, 0, len);
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index 7d6626a..29b279e 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -179,6 +179,9 @@ finalize (GObject *object)
 		priv->decoders = g_slist_delete_link (priv->decoders, priv->decoders);
 	}
 
+	if (priv->tls_certificate)
+		g_object_unref (priv->tls_certificate);
+
 	soup_message_body_free (msg->request_body);
 	soup_message_headers_free (msg->request_headers);
 	soup_message_body_free (msg->response_body);
diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c
index 43c0f04..d56efd1 100644
--- a/libsoup/soup-server.c
+++ b/libsoup/soup-server.c
@@ -79,6 +79,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
 struct SoupClientContext {
 	SoupServer     *server;
 	SoupSocket     *sock;
+	SoupMessage    *msg;
 	SoupAuthDomain *auth_domain;
 	char           *auth_user;
 
@@ -105,7 +106,7 @@ typedef struct {
 	GMainLoop         *loop;
 
 	SoupSocket        *listen_sock;
-	GSList            *client_socks;
+	GSList            *clients;
 
 	gboolean           raw_paths;
 	SoupPathMap       *handlers;
@@ -176,12 +177,19 @@ finalize (GObject *object)
 	if (priv->listen_sock)
 		g_object_unref (priv->listen_sock);
 
-	while (priv->client_socks) {
-		SoupSocket *sock = priv->client_socks->data;
+	while (priv->clients) {
+		SoupClientContext *client = priv->clients->data;
+		SoupSocket *sock = g_object_ref (client->sock);
+
+		priv->clients = g_slist_remove (priv->clients, client);
+
+		if (client->msg) {
+			soup_message_set_status (client->msg, SOUP_STATUS_IO_ERROR);
+			soup_message_io_finished (client->msg);
+		}
 
 		soup_socket_disconnect (sock);
-		priv->client_socks =
-			g_slist_remove (priv->client_socks, sock);
+		g_object_unref (sock);
 	}
 
 	if (priv->default_handler)
@@ -690,6 +698,7 @@ soup_client_context_cleanup (SoupClientContext *client)
 		g_free (client->auth_user);
 		client->auth_user = NULL;
 	}
+	client->msg = NULL;
 }
 
 static SoupClientContext *
@@ -863,6 +872,8 @@ start_request (SoupServer *server, SoupClientContext *client)
 	msg = g_object_new (SOUP_TYPE_MESSAGE,
 			    SOUP_MESSAGE_SERVER_SIDE, TRUE,
 			    NULL);
+	client->msg = msg;
+
 	if (priv->server_header) {
 		soup_message_headers_append (msg->response_headers, "Server",
 					     priv->server_header);
@@ -880,12 +891,12 @@ start_request (SoupServer *server, SoupClientContext *client)
 }
 
 static void
-socket_disconnected (SoupSocket *sock, SoupServer *server)
+socket_disconnected (SoupSocket *sock, SoupClientContext *client)
 {
-	SoupServerPrivate *priv = SOUP_SERVER_GET_PRIVATE (server);
+	SoupServerPrivate *priv = SOUP_SERVER_GET_PRIVATE (client->server);
 
-	priv->client_socks = g_slist_remove (priv->client_socks, sock);
-	g_signal_handlers_disconnect_by_func (sock, socket_disconnected, server);
+	priv->clients = g_slist_remove (priv->clients, client);
+	g_signal_handlers_disconnect_by_func (sock, socket_disconnected, client);
 	g_object_unref (sock);
 }
 
@@ -897,9 +908,9 @@ new_connection (SoupSocket *listner, SoupSocket *sock, gpointer user_data)
 	SoupClientContext *client;
 
 	client = soup_client_context_new (server, g_object_ref (sock));
-	priv->client_socks = g_slist_prepend (priv->client_socks, sock);
+	priv->clients = g_slist_prepend (priv->clients, client);
 	g_signal_connect (sock, "disconnected",
-			  G_CALLBACK (socket_disconnected), server);
+			  G_CALLBACK (socket_disconnected), client);
 	start_request (server, client);
 }
 
diff --git a/libsoup/soup-session-sync.c b/libsoup/soup-session-sync.c
index 344f234..493d8c5 100644
--- a/libsoup/soup-session-sync.c
+++ b/libsoup/soup-session-sync.c
@@ -316,6 +316,7 @@ queue_message_callback (gpointer data)
 
 	item->callback (item->session, item->msg, item->callback_data);
 	g_object_unref (item->session);
+	g_object_unref (item->msg);
 	soup_message_queue_item_unref (item);
 	return FALSE;
 }
@@ -331,6 +332,7 @@ queue_message_thread (gpointer data)
 				     queue_message_callback, item);
 	} else {
 		g_object_unref (item->session);
+		g_object_unref (item->msg);
 		soup_message_queue_item_unref (item);
 	}
 
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index c53d838..4f9d975 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -1315,7 +1315,6 @@ soup_session_make_connect_message (SoupSession    *session,
 	item->conn = g_object_ref (conn);
 	g_object_unref (msg);
 
-	item->conn = g_object_ref (conn);
 	g_signal_emit (session, signals[TUNNELING], 0, conn);
 	return item;
 }
diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c
index b059a5b..8d11841 100644
--- a/libsoup/soup-socket.c
+++ b/libsoup/soup-socket.c
@@ -843,11 +843,13 @@ soup_socket_listen (SoupSocket *sock)
 	priv->watch_src = soup_socket_create_watch (priv, G_IO_IN,
 						    listen_watch, sock,
 						    NULL);
+	g_object_unref (addr);
 	return TRUE;
 
  cant_listen:
 	if (priv->conn)
 		disconnect_internal (sock);
+	g_object_unref (addr);
 
 	return FALSE;
 }
@@ -1439,6 +1441,7 @@ soup_socket_write (SoupSocket *sock, gconstpointer buffer,
 
 	if (g_error_matches (my_err, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
 		g_mutex_unlock (priv->iolock);
+		g_clear_error (&my_err);
 
 		priv->write_src =
 			soup_socket_create_watch (priv,
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 4724d60..5b45a73 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -881,7 +881,7 @@ do_batch_tests (const gchar *base_uri_str, gint ntests)
 {
 	SoupSession *session;
 	SoupMessage *msg;
-	char *expected;
+	char *expected, *uristr;
 	SoupURI *base_uri;
 	int i;
 
@@ -912,7 +912,9 @@ do_batch_tests (const gchar *base_uri_str, gint ntests)
 			exit (1);
 		}
 
-		debug_printf (1, "  GET %s\n", soup_uri_to_string (soup_message_get_uri (msg), FALSE));
+		uristr = soup_uri_to_string (soup_message_get_uri (msg), FALSE);
+		debug_printf (1, "  GET %s\n", uristr);
+		g_free (uristr);
 
 		expected = g_strdup (current_tests[i].expected);
 		soup_message_add_status_code_handler (
diff --git a/tests/libsoup.supp b/tests/libsoup.supp
index cf144a0..69a72ac 100644
--- a/tests/libsoup.supp
+++ b/tests/libsoup.supp
@@ -1,6 +1,22 @@
 # valgrind suppressions file
 
 {
+   ld.so/map
+   Memcheck:Cond
+   fun:index
+   fun:expand_dynamic_string_token
+   fun:_dl_map_object
+}
+{
+   ld.so/relocate
+   Memcheck:Cond
+   fun:_dl_relocate_object
+   fun:dl_main
+   fun:_dl_sysdep_start
+   fun:_dl_start
+}
+
+{
    glib/g_type_init
    Memcheck:Leak
    ...
@@ -79,6 +95,12 @@
    fun:g_quark_from_string
 }
 {
+   glib/g_quark_from_static_string
+   Memcheck:Leak
+   ...
+   fun:g_quark_from_static_string
+}
+{
    glib/get_dispatch
    Memcheck:Leak
    ...
@@ -138,6 +160,43 @@
    ...
    fun:g_get_language_names
 }
+{
+   glib/giomodules
+   Memcheck:Leak
+   ...
+   fun:_g_io_modules_ensure_loaded
+}
+{
+   glib/tlsinit
+   Memcheck:Leak
+   ...
+   fun:get_default_tls_backend
+}
+{
+   glib/tlscrypto
+   Memcheck:Leak
+   ...
+   fun:gcry_pthread_mutex_init
+}
+{
+   glib/tlscache
+   Memcheck:Leak
+   ...
+   fun:g_tls_backend_gnutls_cache_session_data
+}
+{
+   glib/tlspriority
+   Memcheck:Leak
+   ...
+   fun:g_tls_connection_gnutls_init_priorities
+}
+{
+   glib/gfileinfo
+   Memcheck:Leak
+   ...
+   fun:ensure_attribute_hash
+   fun:lookup_attribute
+}
 
 # probably using uninitialized memory as padding or something
 {
@@ -166,23 +225,12 @@
    fun:xmlInitCharEncodingHandlers
 }
 {
-   libsoup/gnutls_1
-   Memcheck:Leak
-   ...
-   fun:soup_gnutls_init
-}
-{
-   libsoup/gnutls_2
+   libxml2/xmlNewCharEncodingHandler
    Memcheck:Leak
    ...
-   fun:init_dh_params
-}
-{
-   libsoup/gnutls_mutexes
-   Memcheck:Leak
-   ...
-   fun:gcry_pthread_mutex_init
+   fun:xmlNewCharEncodingHandler
 }
+
 {
    libsoup/interned_uri_schemes
    Memcheck:Leak
diff --git a/tests/proxy-test.c b/tests/proxy-test.c
index e6e910d..014da39 100644
--- a/tests/proxy-test.c
+++ b/tests/proxy-test.c
@@ -128,8 +128,7 @@ test_url (const char *url, int proxy, guint expected,
 	}
 
 	g_object_unref (msg);
-	soup_session_abort (session);
-	g_object_unref (session);
+	soup_test_session_abort_unref (session);
 }
 
 static void
@@ -198,8 +197,7 @@ do_proxy_fragment_test (SoupURI *base_uri)
 	}
 
 	g_object_unref (msg);
-	soup_session_abort (session);
-	g_object_unref (session);
+	soup_test_session_abort_unref (session);
 }
 
 int
@@ -226,6 +224,7 @@ main (int argc, char **argv)
 
 	soup_uri_free (base_uri);
 	soup_test_server_quit_unref (server);
+
 	test_cleanup ();
 	return errors != 0;
 }



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