diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2024-09-16 16:11:35 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksandermj@chromium.org> | 2024-09-30 11:07:18 +0000 |
commit | a16ad2757dc5c9b94aeb0e4276a4eb3d0007a729 (patch) | |
tree | eec94ea2300cafccab2c03a8746328c341408c8b | |
parent | dfc0f8ebfd6a4a698af6cf784ba749ecdcb05e7e (diff) |
device: don't attempt to export if bus connection has been lost
E.g. if aborting the initialization sequence.
-rw-r--r-- | src/mm-device.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/mm-device.c b/src/mm-device.c index 62cba0fd..73b68fa8 100644 --- a/src/mm-device.c +++ b/src/mm-device.c @@ -348,8 +348,9 @@ unexport_modem (MMDevice *self) static void export_modem (MMDevice *self) { - GDBusConnection *connection = NULL; - gchar *path; + g_autoptr(GDBusConnection) connection = NULL; + g_autofree gchar *existing_path = NULL; + g_autofree gchar *path = NULL; g_assert (MM_IS_BASE_MODEM (self->priv->modem)); g_assert (G_IS_DBUS_OBJECT_MANAGER (self->priv->object_manager)); @@ -360,12 +361,20 @@ export_modem (MMDevice *self) return; } + /* Don't export if we've aborted initialization */ + g_object_get (self->priv->object_manager, + "connection", &connection, + NULL); + if (!connection) { + mm_obj_dbg (self, "exporting aborted as there is no bus connection"); + return; + } + /* Don't export already exported modems */ g_object_get (self->priv->modem, - "g-object-path", &path, + "g-object-path", &existing_path, NULL); - if (path) { - g_free (path); + if (existing_path) { mm_obj_dbg (self, "modem already exported"); return; } @@ -373,9 +382,6 @@ export_modem (MMDevice *self) /* No outstanding port tasks, so if the modem is valid we can export it */ path = g_strdup_printf (MM_DBUS_MODEM_PREFIX "/%d", mm_base_modem_get_dbus_id (self->priv->modem)); - g_object_get (self->priv->object_manager, - "connection", &connection, - NULL); g_object_set (self->priv->modem, "g-object-path", path, MM_BASE_MODEM_CONNECTION, connection, @@ -395,8 +401,6 @@ export_modem (MMDevice *self) (mm_base_modem_get_subsystem_vendor_id (self->priv->modem) & 0xFFFF)); if (self->priv->virtual) mm_obj_dbg (self, " virtual"); - - g_free (path); } /*****************************************************************************/ |