Fix race in g_cancellable_cancel()
authorBenjamin Otte <otte@redhat.com>
Fri, 26 Mar 2010 19:37:09 +0000 (20:37 +0100)
committerRyan Lortie <desrt@desrt.ca>
Mon, 29 Mar 2010 17:57:35 +0000 (12:57 -0500)
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

index 2d600c9..32d01ae 100644 (file)
@@ -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;