core: add and use nm_keep_alive_destroy()

When we are done with a NMKeepAlive instance, we always should do
three things:

  - unset the owner
  - disarm (freeze) the keep-alive
  - give up our reference.

Add and use nm_keep_alive_destroy() that does this.
This commit is contained in:
Thomas Haller 2019-06-27 12:38:45 +02:00
parent dd5c88b1cc
commit 8a8e894f80
3 changed files with 23 additions and 2 deletions

View file

@ -1533,8 +1533,7 @@ finalize (GObject *object)
nm_dbus_track_obj_path_set (&priv->settings_connection, NULL, FALSE);
_nm_keep_alive_set_owner (priv->keep_alive, NULL);
g_clear_object (&priv->keep_alive);
nm_clear_pointer (&priv->keep_alive, nm_keep_alive_destroy);
G_OBJECT_CLASS (nm_active_connection_parent_class)->finalize (object);
}

View file

@ -385,6 +385,26 @@ nm_keep_alive_disarm (NMKeepAlive *self)
cleanup_dbus_watch (self);
}
/**
* nm_keep_alive_destroy:
* @self: (allow-none): the #NMKeepAlive instance to destroy.
*
* This does 3 things in one:
*
* - set owner to %NULL
* - disarm the instance.
* - unref @self.
*/
void
nm_keep_alive_destroy (NMKeepAlive *self)
{
if (!self)
return;
_nm_keep_alive_set_owner (self, NULL);
nm_keep_alive_disarm (self);
g_object_unref (self);
}
/*****************************************************************************/
static void

View file

@ -43,6 +43,8 @@ gboolean nm_keep_alive_is_alive (NMKeepAlive *self);
void nm_keep_alive_arm (NMKeepAlive *self);
void nm_keep_alive_disarm (NMKeepAlive *self);
void nm_keep_alive_destroy (NMKeepAlive *self);
void nm_keep_alive_set_settings_connection_watch_visible (NMKeepAlive *self,
NMSettingsConnection *connection);