diff options
author | Thomas Haller <thaller@redhat.com> | 2019-01-28 11:48:09 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-02-01 17:02:57 +0100 |
commit | 41b2d8c6c996767251d667e36d3a9be2614b9559 (patch) | |
tree | 3870381a9a12356c964c26a6e032422cf4e3797a | |
parent | efbcac25b8f087211039874abd9b03afd3f1c5c6 (diff) | |
download | NetworkManager-41b2d8c6c996767251d667e36d3a9be2614b9559.tar.gz |
libnm/device-p2p-wifi: cleanup peers handling
Don't reallocate peers-array nor set it to %NULL. Instead,
just emit the signal for the peers and take them out one-by-one.
I am slightly surprised, that the peers array does not need to hold
a reference on the NMP2PPeer instances. But that seems intentional.
I think, the libnm code here should be significantly reworked, but
that is for another time.
Also, delay clearing the pointers until finalize() method. For
the most part, it shouldn't make a difference. Still avoid having
the instance in a badly defined state during dispose() (which
theoretically could be called multiple times).
-rw-r--r-- | libnm/nm-device-p2p-wifi.c | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/libnm/nm-device-p2p-wifi.c b/libnm/nm-device-p2p-wifi.c index 4d740fafec..b91392b7e8 100644 --- a/libnm/nm-device-p2p-wifi.c +++ b/libnm/nm-device-p2p-wifi.c @@ -171,31 +171,18 @@ nm_device_p2p_wifi_get_peer_by_path (NMDeviceP2PWifi *device, } static void -clean_up_peers (NMDeviceP2PWifi *self, gboolean in_dispose) +clean_up_peers (NMDeviceP2PWifi *self) { - NMDeviceP2PWifiPrivate *priv; - GPtrArray *peers; - int i; - - g_return_if_fail (NM_IS_DEVICE_P2P_WIFI (self)); - - priv = NM_DEVICE_P2P_WIFI_GET_PRIVATE (self); + NMDeviceP2PWifiPrivate *priv = NM_DEVICE_P2P_WIFI_GET_PRIVATE (self); - peers = priv->peers; + while (priv->peers->len > 0) { + NMP2PPeer *peer; - if (in_dispose) - priv->peers = NULL; - else { - priv->peers = g_ptr_array_new (); + peer = priv->peers->pdata[priv->peers->len - 1]; + g_ptr_array_remove_index (priv->peers, priv->peers->len - 1); - for (i = 0; i < peers->len; i++) { - NMP2PPeer *peer = NM_P2P_PEER (g_ptr_array_index (peers, i)); - - g_signal_emit (self, signals[PEER_REMOVED], 0, peer); - } + g_signal_emit (self, signals[PEER_REMOVED], 0, peer); } - - g_ptr_array_unref (peers); } static gboolean @@ -392,15 +379,7 @@ init_dbus (NMObject *object) static void dispose (GObject *object) { - NMDeviceP2PWifiPrivate *priv = NM_DEVICE_P2P_WIFI_GET_PRIVATE (object); - - if (priv->peers) - clean_up_peers (NM_DEVICE_P2P_WIFI (object), TRUE); - - g_clear_object (&priv->proxy); - if (priv->wfd_ies) - g_byte_array_unref (priv->wfd_ies); - priv->wfd_ies = NULL; + clean_up_peers (NM_DEVICE_P2P_WIFI (object)); G_OBJECT_CLASS (nm_device_p2p_wifi_parent_class)->dispose (object); } @@ -410,7 +389,12 @@ finalize (GObject *object) { NMDeviceP2PWifiPrivate *priv = NM_DEVICE_P2P_WIFI_GET_PRIVATE (object); + g_clear_object (&priv->proxy); g_free (priv->hw_address); + if (priv->wfd_ies) + g_byte_array_unref (priv->wfd_ies); + if (priv->peers) + g_ptr_array_unref (priv->peers); G_OBJECT_CLASS (nm_device_p2p_wifi_parent_class)->finalize (object); } |