[evolution-patches] 36778, file descriptor usage problems




this patch fixes a bug where a file descriptor is closed twice every time a mbox mailbox is synced.

normally this is harmless, but if there is a lot of threading going on, it could lead to data corruption, and possibly this is the cause of bug 36778, and some 'summary mismatch' type bugs, and who knows what else.

i.e.
open() = 12
do processing
close(12)
-> context switch
    open () = 12
<- context switch
close(12)
-> context switch
      any processing on file descriptor  will fail (spurious failures)
<- context switch
open some other file = 12
-> context switch
    any processing on file will corrupt it or interfere with it

etc.

? camel/a.diff
? camel/a.out
? camel/c.diff
? camel/camel-mime-tables.c
? camel/testurl.c
? camel/tests/folder/test10
? camel/tests/folder/test11
? camel/tests/message/test4
? camel/tests/message/trace
? camel/tests/misc/test2
? camel/tests/misc/url-scan
Index: camel/providers/local/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/local/ChangeLog,v
retrieving revision 1.5
diff -u -p -r1.5 ChangeLog
--- camel/providers/local/ChangeLog	17 Mar 2005 02:08:59 -0000	1.5
+++ camel/providers/local/ChangeLog	18 Mar 2005 04:43:24 -0000
@@ -1,3 +1,8 @@
+2005-03-18  Not Zed  <NotZed Ximian com>
+
+	* camel-mbox-summary.c (mbox_summary_sync_quick): use a different
+	fd for the mime parser, so the fd doesn't get closed twice.
+
 2005-03-16  Not Zed  <NotZed Ximian com>
 
 	** See bug #73401?
Index: camel/providers/local/camel-mbox-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/local/camel-mbox-summary.c,v
retrieving revision 1.52
diff -u -p -r1.52 camel-mbox-summary.c
--- camel/providers/local/camel-mbox-summary.c	17 Mar 2005 02:08:59 -0000	1.52
+++ camel/providers/local/camel-mbox-summary.c	18 Mar 2005 04:43:24 -0000
@@ -669,7 +669,7 @@ mbox_summary_sync_quick(CamelMboxSummary
 	CamelMimeParser *mp = NULL;
 	int i, count;
 	CamelMboxMessageInfo *info = NULL;
-	int fd = -1;
+	int fd = -1, pfd;
 	char *xevnew, *xevtmp;
 	const char *xev;
 	int len;
@@ -689,10 +689,20 @@ mbox_summary_sync_quick(CamelMboxSummary
 		return -1;
 	}
 
+	/* need to dup since mime parser closes its fd once it is finalised */
+	pfd = dup(fd);
+	if (pfd == -1) {
+		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
+				     _("Could not store folder: %s"),
+				     g_strerror(errno));
+		close(fd);
+		return -1;
+	}
+
 	mp = camel_mime_parser_new();
 	camel_mime_parser_scan_from(mp, TRUE);
 	camel_mime_parser_scan_pre_from(mp, TRUE);
-	camel_mime_parser_init_with_fd(mp, fd);
+	camel_mime_parser_init_with_fd(mp, pfd);
 
 	count = camel_folder_summary_count(s);
 	for (i = 0; i < count; i++) {


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