From 3b05cbc33b01231b320f513deb1ed320a41f9b52 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 7 Apr 2023 13:23:59 +0200 Subject: [PATCH] core: don't take reference on NMDevice to track auto-activate Add an assertion to nm_policy_device_recheck_auto_activate_schedule(), that the device is currently registered in NMPolicy. Calling it outside would be odd, and likely a bug. But if we only register the auto-activate while being registered, we don't need to take an additional reference. We know that the object must be be alive (also, we have assertions that in fact it is still alive). (cherry picked from commit 0dd4724446fdef043fddc9f1e20569cacb78474d) --- src/core/nm-policy.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index c342fcc53d..f7e1e97344 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -1455,7 +1455,6 @@ _auto_activate_device_clear(NMPolicy *self, NMDevice *device, gboolean do_activa _auto_activate_device(self, device); nm_device_remove_pending_action(device, NM_PENDING_ACTION_AUTOACTIVATE, TRUE); - g_object_unref(device); } static gboolean @@ -1677,6 +1676,14 @@ nm_policy_device_recheck_auto_activate_schedule(NMPolicy *self, NMDevice *device g_return_if_fail(NM_IS_POLICY(self)); g_return_if_fail(NM_IS_DEVICE(device)); + nm_assert(g_signal_handler_find(device, + G_SIGNAL_MATCH_DATA, + 0, + 0, + NULL, + NULL, + NM_POLICY_GET_PRIVATE(self)) + != 0); if (!c_list_is_empty(&device->policy_auto_activate_lst)) { /* already queued. Return. */ @@ -1705,7 +1712,6 @@ nm_policy_device_recheck_auto_activate_schedule(NMPolicy *self, NMDevice *device c_list_link_tail(&priv->policy_auto_activate_lst_head, &device->policy_auto_activate_lst); device->policy_auto_activate_idle_source = nm_g_idle_add_source(_auto_activate_idle_cb, device); - g_object_ref(device); } static gboolean