[gvfs/wip/oholy/trash-deadlock] trash: Explicitly cancel file monitor to prevent deadlock




commit d5b837aa366af8d56465e4a4686781ced87fe5a2
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Sep 8 17:33:28 2020 +0200

    trash: Explicitly cancel file monitor to prevent deadlock
    
    It seems that if file monitor is not canceled before unreffing, it can
    cause deadlock. Let's explicitly cancel it before unreffing to prevent
    this. See https://gitlab.gnome.org/GNOME/glib/-/issues/1941.
    
    Fixes: https://gitlab.gnome.org/GNOME/gvfs/-/issues/485

 daemon/trashlib/dirwatch.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/daemon/trashlib/dirwatch.c b/daemon/trashlib/dirwatch.c
index f2bc69248..6a2f1f6f4 100644
--- a/daemon/trashlib/dirwatch.c
+++ b/daemon/trashlib/dirwatch.c
@@ -216,6 +216,7 @@ dir_watch_recursive_destroy (gpointer user_data)
       watch->state = FALSE;
     }
 
+  g_file_monitor_cancel (watch->parent_monitor);
   g_object_unref (watch->parent_monitor);
   watch->parent_monitor = NULL;
 }
@@ -271,7 +272,10 @@ dir_watch_free (DirWatch *watch)
   if (watch != NULL)
     {
       if (watch->parent_monitor)
-        g_object_unref (watch->parent_monitor);
+        {
+          g_file_monitor_cancel (watch->parent_monitor);
+          g_object_unref (watch->parent_monitor);
+        }
 
       g_object_unref (watch->directory);
       g_object_unref (watch->topdir);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]