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 0dd4724446)
This commit is contained in:
Thomas Haller 2023-04-07 13:23:59 +02:00
parent 5fddc6d723
commit 3b05cbc33b
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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