[banshee] [gio] Dispose FileEnumerator when done with it



commit 5c81b79964dbf075e95bb611da69e56071eaa567
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Thu Mar 18 15:05:26 2010 -0700

    [gio] Dispose FileEnumerator when done with it
    
    Prevents leaking file descriptors, eventually taking them all up, which
    leads to all sorts of issues (w/ sqlite, etc) bgo#613182

 .../Banshee.Gio/Banshee.IO.Gio/Directory.cs        |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs
index a2283e7..41b4162 100644
--- a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs
+++ b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs
@@ -117,7 +117,8 @@ namespace Banshee.IO.Gio
 
         private IEnumerable<string> GetFiles (GLib.File dir, bool followSymlinks)
         {
-            foreach (FileInfo file in dir.EnumerateChildren ("standard::type,standard::name", followSymlinks ? FileQueryInfoFlags.None : FileQueryInfoFlags.NofollowSymlinks, null)) {
+            var enumerator = dir.EnumerateChildren ("standard::type,standard::name", followSymlinks ? FileQueryInfoFlags.None : FileQueryInfoFlags.NofollowSymlinks, null);
+            foreach (FileInfo file in enumerator) {
                 if ((file.FileType & FileType.Regular) != 0) {
                     var ret = dir.Uri.AbsoluteUri + "/" + Uri.EscapeDataString (file.Name);
                     file.Dispose ();
@@ -126,6 +127,10 @@ namespace Banshee.IO.Gio
                     file.Dispose ();
                 }
             }
+            if (!enumerator.IsClosed) {
+                enumerator.Close (null);
+                enumerator.Dispose ();
+            }
         }
 
         public IEnumerable<string> GetDirectories (string directory)
@@ -135,7 +140,8 @@ namespace Banshee.IO.Gio
 
         private IEnumerable<string> GetDirectories (GLib.File dir, bool followSymlinks)
         {
-            foreach (FileInfo file in dir.EnumerateChildren ("standard::type,standard::name", followSymlinks ? FileQueryInfoFlags.None : FileQueryInfoFlags.NofollowSymlinks, null)) {
+            var enumerator = dir.EnumerateChildren ("standard::type,standard::name", followSymlinks ? FileQueryInfoFlags.None : FileQueryInfoFlags.NofollowSymlinks, null);
+            foreach (FileInfo file in enumerator) {
                 if ((file.FileType & FileType.Directory) != 0) {
                     var ret = dir.Uri.AbsoluteUri + "/" + Uri.EscapeDataString (file.Name);
                     file.Dispose ();
@@ -144,6 +150,10 @@ namespace Banshee.IO.Gio
                     file.Dispose ();
                 }
             }
+            if (!enumerator.IsClosed) {
+                enumerator.Close (null);
+                enumerator.Dispose ();
+            }
         }
 
         public void Move (SafeUri from, SafeUri to)
@@ -152,4 +162,4 @@ namespace Banshee.IO.Gio
             dir.Move (FileFactory.NewForUri (to.AbsoluteUri), FileCopyFlags.None, null, null);
         }
     }
-}
\ No newline at end of file
+}



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