open() and cancellation - #123472



Hi,

Bug #123472 has been biting us here at Novell because people mount
netware filesystems (!) and Nautilus leaks file handles.  It does this
while opening and reading text files to generate icons for them.

I just submitted a patch to bugzilla.  It patches file-method.c.

Although the bug report mentions that handles may be leaked for any
method which does not handle cancellation on its own, I think
file-method is by far the most important.

Does the patch seem reasonable?  It certainly fixes the problem with
text files for me.

Thanks,

  Federico
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-vfs/ChangeLog,v
retrieving revision 1.2233
diff -u -r1.2233 ChangeLog
--- ChangeLog	28 Jul 2005 01:34:30 -0000	1.2233
+++ ChangeLog	1 Aug 2005 23:10:51 -0000
@@ -1,3 +1,9 @@
+2005-08-01  Federico Mena Quintero  <federico ximian com>
+
+	* modules/file-method.c (do_open): If open() succeeds, check the
+	context's cancellation.  If we got canceled, close() the fd.
+	Fixes the file-method part of bug #123472.
+
 2005-07-28  Tor Lillqvist  <tml novell com>
 
 	* imported/neon/Makefile.am (libneon_la_LDFLAGS): As libneon is a
Index: modules/file-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/file-method.c,v
retrieving revision 1.144
diff -u -r1.144 file-method.c
--- modules/file-method.c	15 Jul 2005 13:46:53 -0000	1.144
+++ modules/file-method.c	1 Aug 2005 23:10:51 -0000
@@ -331,6 +331,15 @@
 
 	if (fd == -1)
 		return gnome_vfs_result_from_errno ();
+	else if (gnome_vfs_context_check_cancellation (context)) {
+		int result;
+
+		do {
+			result = close (fd);
+		} while (result == -1 && errno == EINTR);
+
+		return GNOME_VFS_ERROR_CANCELLED;
+	}
 
 #ifdef HAVE_POSIX_FADVISE
 	if (! (mode & GNOME_VFS_OPEN_RANDOM)) {


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