From e7763678b56e3be073cc55d707a6e92fc2055ee0 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 26 Mar 2010 20:37:09 +0100 Subject: [PATCH] Fix race in g_cancellable_cancel() We need to check priv->cancelled after taking the lock. Previously we only checked it just before taking the lock, which left a small chance for a race. --- gio/gcancellable.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gio/gcancellable.c b/gio/gcancellable.c index 2d600c91e..32d01aeb1 100644 --- a/gio/gcancellable.c +++ b/gio/gcancellable.c @@ -622,6 +622,11 @@ g_cancellable_cancel (GCancellable *cancellable) priv = cancellable->priv; G_LOCK(cancellable); + if (priv->cancelled) + { + G_UNLOCK (cancellable); + return; + } priv->cancelled = TRUE; priv->cancelled_running = TRUE;