diff options
-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); } /*****************************************************************************/ |