diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index 17fb82e50..625c19e83 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -156,6 +156,20 @@ _settings_connection_updated (NMSettingsConnection *connection, * settings-connection. */ } +static void +_settings_connection_removed (NMSettingsConnection *connection, + gpointer user_data) +{ + NMActiveConnection *self = user_data; + + /* Our settings connection is about to drop off. The next active connection + * cleanup is going to tear us down (at least until we grow the capability to + * re-link; in that case we'd just clean the references to the old connection here). + * Let's remove ourselves from the bus so that we're not exposed with a dangling + * reference to the setting connection once it's gone. */ + nm_exported_object_unexport (NM_EXPORTED_OBJECT (self)); +} + static void _set_settings_connection (NMActiveConnection *self, NMSettingsConnection *connection) { @@ -170,6 +184,7 @@ _set_settings_connection (NMActiveConnection *self, NMSettingsConnection *connec if (connection) { priv->settings_connection = g_object_ref (connection); g_signal_connect (connection, NM_SETTINGS_CONNECTION_UPDATED_INTERNAL, (GCallback) _settings_connection_updated, self); + g_signal_connect (connection, NM_SETTINGS_CONNECTION_REMOVED, (GCallback) _settings_connection_removed, self); } } diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 6a920d5cf..35790a126 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -1112,8 +1112,10 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection) openconnect_migrate_hack (NM_CONNECTION (connection)); g_object_ref (self); - g_signal_connect (connection, NM_SETTINGS_CONNECTION_REMOVED, - G_CALLBACK (connection_removed), self); + /* This one unexports the connection, it needs to run late to give the active + * connection a chance to deal with its reference to this settings connection. */ + g_signal_connect_after (connection, NM_SETTINGS_CONNECTION_REMOVED, + G_CALLBACK (connection_removed), self); g_signal_connect (connection, NM_SETTINGS_CONNECTION_UPDATED_INTERNAL, G_CALLBACK (connection_updated), self); g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_VISIBLE,