Commit 68ba774f authored by Julian Bouzas's avatar Julian Bouzas
Browse files

endpoint: steal the endpoint link from the list before destroying it

The wp_endpoint_link_destroy API removes the link from both endpoints. If this
is called in the endpoint destructor, we need to make sure the link is not in
the endpoint link list (by stealing it) to prevent the API destroying it again.
parent 73978f76
Pipeline #79590 passed with stage
in 5 minutes and 28 seconds
......@@ -170,12 +170,13 @@ wp_endpoint_dispose (GObject * object)
{
WpEndpointPrivate *priv =
wp_endpoint_get_instance_private (WP_ENDPOINT (object));
gint i;
WpEndpointLink *l = NULL;
/* wp_endpoint_link_destroy removes elements from the array,
* so traversing in reverse order is faster and less complicated */
for (i = priv->links->len - 1; i >= 0; i--) {
wp_endpoint_link_destroy (g_ptr_array_index (priv->links, i));
* so traversing in reverse order is er and less complicated */
while (priv->links->len > 0) {
l = g_ptr_array_steal_index (priv->links, priv->links->len - 1);
wp_endpoint_link_destroy(l);
}
G_OBJECT_CLASS (wp_endpoint_parent_class)->dispose (object);
......@@ -371,6 +372,7 @@ wp_endpoint_unregister (WpEndpoint * self)
{
WpEndpointPrivate *priv;
g_autoptr (WpCore) core = NULL;
WpEndpointLink *l = NULL;
g_return_if_fail (WP_IS_ENDPOINT (self));
......@@ -378,8 +380,10 @@ wp_endpoint_unregister (WpEndpoint * self)
/* unlink before unregistering so that policy modules
* can find dangling unlinked endpoints */
for (gint i = priv->links->len - 1; i >= 0; i--)
wp_endpoint_link_destroy (g_ptr_array_index (priv->links, i));
while (priv->links->len > 0) {
l = g_ptr_array_steal_index_fast(priv->links, priv->links->len - 1);
wp_endpoint_link_destroy(l);
}
core = g_weak_ref_get (&priv->core);
if (core) {
......@@ -742,14 +746,16 @@ void
wp_endpoint_unlink (WpEndpoint * self)
{
WpEndpointPrivate *priv;
gint i;
WpEndpointLink *l = NULL;
g_return_if_fail (WP_IS_ENDPOINT (self));
priv = wp_endpoint_get_instance_private (self);
for (i = priv->links->len - 1; i >= 0; i--)
wp_endpoint_link_destroy (g_ptr_array_index (priv->links, i));
while (priv->links->len > 0) {
l = g_ptr_array_steal_index_fast(priv->links, priv->links->len - 1);
wp_endpoint_link_destroy(l);
}
}
......
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