From 8627fdf1a0db0b0d354d778c11d9410d66d23fc5 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Tue, 2 Jun 2020 18:37:42 +0300
Subject: [PATCH] proxy: fix crash when _augment_error() is called recursively
 from within itself

---
 lib/wp/proxy.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/wp/proxy.c b/lib/wp/proxy.c
index 04e0d90b..835ca37e 100644
--- a/lib/wp/proxy.c
+++ b/lib/wp/proxy.c
@@ -546,18 +546,24 @@ void
 wp_proxy_augment_error (WpProxy * self, GError * error)
 {
   WpProxyPrivate *priv;
-  guint i;
 
   g_return_if_fail (WP_IS_PROXY (self));
 
   priv = wp_proxy_get_instance_private (self);
 
-  for (i = 0; i < priv->augment_tasks->len; i++) {
-    GTask *task = g_ptr_array_index (priv->augment_tasks, i);
-    g_task_return_error (task, g_error_copy (error));
+  /* steal the array to avoid recursion here */
+  if (priv->augment_tasks->len > 0) {
+    guint i;
+    g_autoptr (GPtrArray) augment_tasks =
+        g_steal_pointer (&priv->augment_tasks);
+    priv->augment_tasks = g_ptr_array_new_with_free_func (g_object_unref);
+
+    for (i = 0; i < augment_tasks->len; i++) {
+      GTask *task = g_ptr_array_index (augment_tasks, i);
+      g_task_return_error (task, g_error_copy (error));
+    }
   }
 
-  g_ptr_array_set_size (priv->augment_tasks, 0);
   g_error_free (error);
 }
 
-- 
GitLab