From b770cf6a3eae56d30ec38447bb7fad63bff4777d Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Tue, 18 Jun 2019 19:39:52 +0300
Subject: [PATCH] core: remove_global: remove object from the list before
 triggering the notification

This avoids being able to find the same object on the globals list
from code that is connected to the signal.
---
 lib/wp/core.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/wp/core.c b/lib/wp/core.c
index f6610bc4..326e9b98 100644
--- a/lib/wp/core.c
+++ b/lib/wp/core.c
@@ -193,6 +193,7 @@ wp_core_remove_global (WpCore * self, GQuark key, gpointer obj)
 {
   gint i;
   struct global_object *global;
+  struct global_object tmp;
 
   g_return_if_fail (WP_IS_CORE (self));
 
@@ -206,13 +207,15 @@ wp_core_remove_global (WpCore * self, GQuark key, gpointer obj)
   }
 
   if (i < self->global_objects->len) {
-    g_signal_emit (self, signals[SIGNAL_GLOBAL_REMOVED], key,
-        key, global->object);
-
-    if (global->destroy)
-      global->destroy (global->object);
+    tmp = *global;
 
     g_ptr_array_remove_index_fast (self->global_objects, i);
+
+    g_signal_emit (self, signals[SIGNAL_GLOBAL_REMOVED], key,
+        key, tmp.object);
+
+    if (tmp.destroy)
+      tmp.destroy (tmp.object);
   }
 }
 
-- 
GitLab