soup-connection.c: do not unref the socket twice while disconnecting
authorSergio Villar Senin <svillar@igalia.com>
Wed, 28 Mar 2012 08:29:49 +0000 (10:29 +0200)
committerSergio Villar Senin <svillar@igalia.com>
Wed, 28 Mar 2012 15:55:52 +0000 (17:55 +0200)
Reentrant calls to soup_socket_disconnect() when disconnecting the socket
lead to double disconnections and double unref of the same SoupSocket.

https://bugzilla.gnome.org/show_bug.cgi?id=672178

libsoup/soup-connection.c

index b299e2b..ad4e8e6 100644 (file)
@@ -842,11 +842,16 @@ soup_connection_disconnect (SoupConnection *conn)
                soup_connection_set_state (conn, SOUP_CONNECTION_DISCONNECTED);
 
        if (priv->socket) {
-               g_signal_handlers_disconnect_by_func (priv->socket,
-                                                     socket_disconnected, conn);
-               soup_socket_disconnect (priv->socket);
-               g_object_unref (priv->socket);
+               /* Set the socket to NULL at the beginning to avoid reentrancy
+                * issues. soup_socket_disconnect() could trigger a reentrant
+                * call unref'ing and disconnecting the socket twice.
+                */
+               SoupSocket *socket = priv->socket;
                priv->socket = NULL;
+               g_signal_handlers_disconnect_by_func (socket,
+                                                     socket_disconnected, conn);
+               soup_socket_disconnect (socket);
+               g_object_unref (socket);
        }
 
        if (old_state != SOUP_CONNECTION_DISCONNECTED)