Cancel the GDBusObjectManager operation to fix a potential crash

If blues takes longer than 1500ms to successfully start, then we will call
fu_bluez_backend_connect_cb() with a freed FuBluezBackendHelper.

Hopefully fixes https://bugzilla.redhat.com/show_bug.cgi?id=1949491
This commit is contained in:
Richard Hughes 2021-04-14 18:02:01 +01:00
parent 9cf5f8f7ff
commit 1eec68e2c6

View File

@ -117,6 +117,7 @@ typedef struct {
GDBusObjectManager *object_manager; GDBusObjectManager *object_manager;
GMainLoop *loop; GMainLoop *loop;
GError **error; GError **error;
GCancellable *cancellable;
guint timeout_id; guint timeout_id;
} FuBluezBackendHelper; } FuBluezBackendHelper;
@ -127,6 +128,7 @@ fu_bluez_backend_helper_free (FuBluezBackendHelper *helper)
g_object_unref (helper->object_manager); g_object_unref (helper->object_manager);
if (helper->timeout_id != 0) if (helper->timeout_id != 0)
g_source_remove (helper->timeout_id); g_source_remove (helper->timeout_id);
g_cancellable_cancel (helper->cancellable);
g_main_loop_unref (helper->loop); g_main_loop_unref (helper->loop);
g_free (helper); g_free (helper);
} }
@ -148,12 +150,7 @@ static gboolean
fu_bluez_backend_timeout_cb (gpointer user_data) fu_bluez_backend_timeout_cb (gpointer user_data)
{ {
FuBluezBackendHelper *helper = (FuBluezBackendHelper *) user_data; FuBluezBackendHelper *helper = (FuBluezBackendHelper *) user_data;
g_set_error (helper->error, g_cancellable_cancel (helper->cancellable);
G_IO_ERROR,
G_IO_ERROR_TIMED_OUT,
"failed to connect to Bluez after %ums",
(guint) FU_BLUEZ_BACKEND_TIMEOUT);
g_main_loop_quit (helper->loop);
helper->timeout_id = 0; helper->timeout_id = 0;
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
@ -168,6 +165,7 @@ fu_bluez_backend_setup (FuBackend *backend, GError **error)
* forever and make fwupd startup also fail */ * forever and make fwupd startup also fail */
helper->error = error; helper->error = error;
helper->loop = g_main_loop_new (NULL, FALSE); helper->loop = g_main_loop_new (NULL, FALSE);
helper->cancellable = g_cancellable_new ();
helper->timeout_id = g_timeout_add (FU_BLUEZ_BACKEND_TIMEOUT, helper->timeout_id = g_timeout_add (FU_BLUEZ_BACKEND_TIMEOUT,
fu_bluez_backend_timeout_cb, fu_bluez_backend_timeout_cb,
helper); helper);
@ -176,7 +174,8 @@ fu_bluez_backend_setup (FuBackend *backend, GError **error)
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
"org.bluez", "org.bluez",
"/", "/",
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
helper->cancellable,
fu_bluez_backend_connect_cb, fu_bluez_backend_connect_cb,
helper); helper);
g_main_loop_run (helper->loop); g_main_loop_run (helper->loop);