summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-11-17 12:56:14 +0100
committerThomas Haller <thaller@redhat.com>2018-11-17 13:13:38 +0100
commit3baf56b4741435b6092ec2b2d9a1c2704f685b95 (patch)
tree585423be238d085b4320b9d18f59c046ec9d4a0a
parentbe91d1cc4ef047a0a9f41711669f13d28f5fa906 (diff)
downloadNetworkManager-3baf56b4741435b6092ec2b2d9a1c2704f685b95.tar.gz
keep-alive: cleanup tracking visible state of connection
- in nm_keep_alive_set_settings_connection_watch_visible(), abort early when setting the same connection again (or %NULL again). - nm_keep_alive_set_settings_connection_watch_visible() would (already before) correctly disconnect the signal handler from the previous connection. As we anyway do explict disconnects, avoid the overhead of a weak pointer with g_signal_connect_object(). Just reuse the same setter to disconnect the signal in dispose(). - fix leaking priv->connection in nm_keep_alive_set_settings_connection_watch_visible(). - use g_signal_handlers_disconnect_by_func(), to be more specific about which signal we want to disconnect.
-rw-r--r--src/nm-keep-alive.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/nm-keep-alive.c b/src/nm-keep-alive.c
index 4d67d907be..cfad13e6a3 100644
--- a/src/nm-keep-alive.c
+++ b/src/nm-keep-alive.c
@@ -135,22 +135,41 @@ connection_flags_changed (NMSettingsConnection *connection,
_notify_alive (self);
}
-void
-nm_keep_alive_set_settings_connection_watch_visible (NMKeepAlive *self,
- NMSettingsConnection *connection)
+static void
+_set_settings_connection_watch_visible (NMKeepAlive *self,
+ NMSettingsConnection *connection,
+ gboolean emit_signal)
{
NMKeepAlivePrivate *priv = NM_KEEP_ALIVE_GET_PRIVATE (self);
+ gs_unref_object NMSettingsConnection *old_connection = NULL;
+
+ if (priv->connection == connection)
+ return;
if (priv->connection) {
- g_signal_handlers_disconnect_by_data (priv->connection, self);
- priv->connection = NULL;
+ g_signal_handlers_disconnect_by_func (priv->connection,
+ G_CALLBACK (connection_flags_changed),
+ self);
+ old_connection = g_steal_pointer (&priv->connection);
}
- priv->connection = g_object_ref (connection);
- g_signal_connect_object (priv->connection, NM_SETTINGS_CONNECTION_FLAGS_CHANGED,
- G_CALLBACK (connection_flags_changed), self, 0);
+ if (connection) {
+ priv->connection = g_object_ref (connection);
+ g_signal_connect (priv->connection,
+ NM_SETTINGS_CONNECTION_FLAGS_CHANGED,
+ G_CALLBACK (connection_flags_changed),
+ self);
+ }
- _notify_alive (self);
+ if (emit_signal)
+ _notify_alive (self);
+}
+
+void
+nm_keep_alive_set_settings_connection_watch_visible (NMKeepAlive *self,
+ NMSettingsConnection *connection)
+{
+ _set_settings_connection_watch_visible (self, connection, TRUE);
}
/*****************************************************************************/
@@ -265,10 +284,8 @@ static void
dispose (GObject *object)
{
NMKeepAlive *self = NM_KEEP_ALIVE (object);
- NMKeepAlivePrivate *priv = NM_KEEP_ALIVE_GET_PRIVATE (self);
-
- g_clear_object (&priv->connection);
+ _set_settings_connection_watch_visible (self, NULL, FALSE);
cleanup_dbus_watch (self);
}