Commit 41b2d8c6 authored by Thomas Haller's avatar Thomas Haller
Browse files

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).
parent efbcac25
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment