From a779dd38494e89eb91c4dc1fe23fcc5de321137f Mon Sep 17 00:00:00 2001 From: Ell Date: Fri, 30 Nov 2018 03:09:21 -0500 Subject: [PATCH] app: unref async when removing last callback if idle is pending In gimp_async_remove_callback(), if removing the last callback while the callback idle-source is already pending, cancel the idle source and unref the async object (the async is reffed when adding the idle source.) --- app/core/gimpasync.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/core/gimpasync.c b/app/core/gimpasync.c index b1f3e932b7..7a57f0f674 100644 --- a/app/core/gimpasync.c +++ b/app/core/gimpasync.c @@ -467,7 +467,8 @@ gimp_async_remove_callback (GimpAsync *async, GimpAsyncCallback callback, gpointer data) { - GList *iter; + GList *iter; + gboolean unref_async = FALSE; g_return_if_fail (GIMP_IS_ASYNC (async)); g_return_if_fail (callback != NULL); @@ -492,7 +493,18 @@ gimp_async_remove_callback (GimpAsync *async, iter = next; } + if (g_queue_is_empty (&async->priv->callbacks) && async->priv->idle_id) + { + g_source_remove (async->priv->idle_id); + async->priv->idle_id = 0; + + unref_async = TRUE; + } + g_mutex_unlock (&async->priv->mutex); + + if (unref_async) + g_object_unref (async); } /* checks if 'async' is in the "stopped" state.