mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 20:46:14 +01:00
gcancellable: Reference the object before locking when doing signal emission
On g_cancellable_cancel() we were increasing the GCancellable ref count before emitting the ::cancelled signal, this is a safe thing to do but it was happening while the cancellable was locked, and this may have potentially waken up some toggle notifications. To prevent this, reference the GCancellable just before locking.
This commit is contained in:
parent
3a07b2abd4
commit
54d9c26b34
@ -495,11 +495,16 @@ g_cancellable_cancel (GCancellable *cancellable)
|
||||
|
||||
priv = cancellable->priv;
|
||||
|
||||
/* We add a reference before locking, to avoid that potential toggle
|
||||
* notifications on the object might happen while we're locked.
|
||||
*/
|
||||
g_object_ref (cancellable);
|
||||
g_mutex_lock (&priv->mutex);
|
||||
|
||||
if (!g_atomic_int_compare_and_exchange (&priv->cancelled, FALSE, TRUE))
|
||||
{
|
||||
g_mutex_unlock (&priv->mutex);
|
||||
g_object_unref (cancellable);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -508,7 +513,6 @@ g_cancellable_cancel (GCancellable *cancellable)
|
||||
if (priv->wakeup)
|
||||
GLIB_PRIVATE_CALL (g_wakeup_signal) (priv->wakeup);
|
||||
|
||||
g_object_ref (cancellable);
|
||||
g_signal_emit (cancellable, signals[CANCELLED], 0);
|
||||
|
||||
if (g_atomic_int_dec_and_test (&priv->cancelled_running))
|
||||
|
Loading…
Reference in New Issue
Block a user