Backport MR #374 to fix some crashes

This should fix a crash that quite often affects Calculator and
a couple of other apps in openQA testing.
This commit is contained in:
Adam Williamson 2023-08-25 15:20:22 -07:00
parent 8626bb2afa
commit 7256cdaa42
3 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,79 @@
From 31d415ca44349fe8c4d2e0b2fb56f84501ec9524 Mon Sep 17 00:00:00 2001
From: Michael Catanzaro <mcatanzaro@redhat.com>
Date: Mon, 21 Aug 2023 12:54:53 -0500
Subject: [PATCH 1/2] connection-manager: don't crash if connection outlives
its manager
I have no clue whether SoupConnections are expected to outlive
SoupConnectionManager or not, but it's happening, and it doesn't seem too
surprising; after all, SoupConnection is a GObject, and things can keep
references to it. Guard against this by disconnecting from the signals
of each SoupConnection when destroying the SoupConnectionManager.
Probably fixes #361
---
libsoup/soup-connection-manager.c | 34 +++++++++++++++++++++----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/libsoup/soup-connection-manager.c b/libsoup/soup-connection-manager.c
index e6f7caa7..5c4ec741 100644
--- a/libsoup/soup-connection-manager.c
+++ b/libsoup/soup-connection-manager.c
@@ -206,6 +206,26 @@ soup_connection_manager_get_or_create_host_for_item (SoupConnectionManager *mana
return host;
}
+static void
+soup_connection_manager_drop_connection (SoupConnectionManager *manager,
+ SoupConnection *conn)
+{
+ g_signal_handlers_disconnect_by_data (conn, manager);
+ manager->num_conns--;
+ g_object_unref (conn);
+
+ g_cond_broadcast (&manager->cond);
+}
+
+static void
+remove_connection (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ SoupConnectionManager *manager = user_data;
+ soup_connection_manager_drop_connection (manager, key);
+}
+
SoupConnectionManager *
soup_connection_manager_new (SoupSession *session,
guint max_conns,
@@ -235,6 +255,9 @@ soup_connection_manager_new (SoupSession *session,
void
soup_connection_manager_free (SoupConnectionManager *manager)
{
+ g_hash_table_foreach (manager->conns, remove_connection, manager);
+ g_assert (manager->num_conns == 0);
+
g_clear_object (&manager->remote_connectable);
g_hash_table_destroy (manager->http_hosts);
g_hash_table_destroy (manager->https_hosts);
@@ -293,17 +316,6 @@ soup_connection_manager_get_num_conns (SoupConnectionManager *manager)
return manager->num_conns;
}
-static void
-soup_connection_manager_drop_connection (SoupConnectionManager *manager,
- SoupConnection *conn)
-{
- g_signal_handlers_disconnect_by_data (conn, manager);
- manager->num_conns--;
- g_object_unref (conn);
-
- g_cond_broadcast (&manager->cond);
-}
-
static void
soup_connection_list_disconnect_all (GList *conns)
{
--
2.41.0

View File

@ -0,0 +1,34 @@
From c978ab757ab62b295e65936858758fdf7e67b6bc Mon Sep 17 00:00:00 2001
From: Michael Catanzaro <mcatanzaro@redhat.com>
Date: Mon, 21 Aug 2023 12:56:55 -0500
Subject: [PATCH 2/2] connection-auth: don't crash if connection outlives the
auth
Currently we crash if the SoupConnection lives longer than the
SoupConnectionAuth. I'm unsure whether this is intended to happen, but
since it does happen, we should probably disconnect from the
SoupConnection's signal rather than crash when it does.
Probably fixes #348
---
libsoup/auth/soup-connection-auth.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libsoup/auth/soup-connection-auth.c b/libsoup/auth/soup-connection-auth.c
index 2d9514f9..34d40d12 100644
--- a/libsoup/auth/soup-connection-auth.c
+++ b/libsoup/auth/soup-connection-auth.c
@@ -113,8 +113,8 @@ soup_connection_auth_get_connection_state_for_message (SoupConnectionAuth *auth,
g_hash_table_insert (priv->conns, conn, state);
g_mutex_unlock (&priv->lock);
if (conn) {
- g_signal_connect (conn, "disconnected",
- G_CALLBACK (connection_disconnected), auth);
+ g_signal_connect_object (conn, "disconnected",
+ G_CALLBACK (connection_disconnected), auth, 0);
}
} else {
g_mutex_unlock (&priv->lock);
--
2.41.0

View File

@ -8,6 +8,13 @@ Summary: Soup, an HTTP library implementation
License: LGPL-2.0-or-later
URL: https://wiki.gnome.org/Projects/libsoup
Source0: https://download.gnome.org/sources/libsoup/3.4/libsoup-%{version}.tar.xz
# https://gitlab.gnome.org/GNOME/libsoup/-/merge_requests/374
# https://gitlab.gnome.org/GNOME/libsoup/-/issues/361
# https://gitlab.gnome.org/GNOME/libsoup/-/issues/348
# Fixes a couple of cases where apps can crash in connection_disconnect()
Patch: 0001-connection-manager-don-t-crash-if-connection-outlive.patch
Patch: 0002-connection-auth-don-t-crash-if-connection-outlives-t.patch
BuildRequires: gcc
BuildRequires: gettext