[gvfs] MTP: Fix leaked weak reference on monitors.

commit 3e0e4d0d9b47d27562e450d45762aa5135320c1f
Author: Philip Langdale <philipl overt org>
Date:   Wed Jan 23 11:54:29 2013 -0800

    MTP: Fix leaked weak reference on monitors.
    We use a weak reference to automatically clean up the monitor
    hash table when monitors are finalized. However, we still need
    to remember to remove the weak references when the backend is
    itself finalized - otherwise the reference might be fired later
    if a monitor happens to get finalized before the backend exits

 daemon/gvfsbackendmtp.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
index a39e4d1..efd1943 100644
--- a/daemon/gvfsbackendmtp.c
+++ b/daemon/gvfsbackendmtp.c
@@ -131,6 +131,14 @@ g_vfs_backend_mtp_init (GVfsBackendMtp *backend)
 static void
+remove_monitor_weak_ref (gpointer monitor,
+                         gpointer unused,
+                         gpointer monitors)
+  g_object_weak_unref (G_OBJECT(monitor), (GWeakNotify)g_hash_table_remove, monitors);
+static void
 g_vfs_backend_mtp_finalize (GObject *object)
   GVfsBackendMtp *backend;
@@ -139,6 +147,7 @@ g_vfs_backend_mtp_finalize (GObject *object)
   backend = G_VFS_BACKEND_MTP (object);
+  g_hash_table_foreach (backend->monitors, remove_monitor_weak_ref, backend->monitors);
   g_hash_table_unref (backend->monitors);
   g_mutex_clear (&backend->mutex);

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