Fix memory leaks, update libsoup.supp
authorDan Winship <danw@gnome.org>
Mon, 28 Mar 2011 18:59:00 +0000 (14:59 -0400)
committerDan Winship <danw@gnome.org>
Thu, 7 Apr 2011 13:29:03 +0000 (09:29 -0400)
libsoup/soup-auth-basic.c
libsoup/soup-message.c
libsoup/soup-server.c
libsoup/soup-session-sync.c
libsoup/soup-session.c
libsoup/soup-socket.c
tests/auth-test.c
tests/libsoup.supp
tests/proxy-test.c

index cf8bf47..4218f7e 100644 (file)
@@ -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);
index 7d6626a..29b279e 100644 (file)
@@ -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);
index 43c0f04..d56efd1 100644 (file)
@@ -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);
 }
 
index 344f234..493d8c5 100644 (file)
@@ -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);
        }
 
index c53d838..4f9d975 100644 (file)
@@ -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;
 }
index b059a5b..8d11841 100644 (file)
@@ -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,
index 4724d60..5b45a73 100644 (file)
@@ -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 (
index cf144a0..69a72ac 100644 (file)
@@ -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
    ...
    fun:g_quark_from_string
 }
 {
+   glib/g_quark_from_static_string
+   Memcheck:Leak
+   ...
+   fun:g_quark_from_static_string
+}
+{
    glib/get_dispatch
    Memcheck:Leak
    ...
    ...
    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
 {
    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
index e6e910d..014da39 100644 (file)
@@ -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;
 }