[dovecot-cvs] dovecot/src/lib-index mail-transaction-log-private.h, 1.13, 1.13.2.1 mail-transaction-log.c, 1.111.2.1, 1.111.2.2

tss at dovecot.org tss at dovecot.org
Wed Nov 8 17:04:01 UTC 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv2664

Modified Files:
      Tag: branch_1_0
	mail-transaction-log-private.h mail-transaction-log.c 
Log Message:
Don't leak opened .log.2 transaction logs.



Index: mail-transaction-log-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log-private.h,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -u -d -r1.13 -r1.13.2.1
--- mail-transaction-log-private.h	13 Jan 2006 20:26:13 -0000	1.13
+++ mail-transaction-log-private.h	8 Nov 2006 17:03:58 -0000	1.13.2.1
@@ -38,6 +38,8 @@
 struct mail_transaction_log {
 	struct mail_index *index;
         struct mail_transaction_log_view *views;
+	/* head is the latest log file. tail is a linked list of older
+	   files. head isn't part of that linked list at all (ugh) */
 	struct mail_transaction_log_file *head, *tail;
 
 	unsigned int dotlock_count;

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.111.2.1
retrieving revision 1.111.2.2
diff -u -d -r1.111.2.1 -r1.111.2.2
--- mail-transaction-log.c	17 Jun 2006 13:42:36 -0000	1.111.2.1
+++ mail-transaction-log.c	8 Nov 2006 17:03:58 -0000	1.111.2.2
@@ -267,10 +267,10 @@
 
 	mail_transaction_log_views_close(log);
 
-	if (log->head != NULL) {
+	if (log->head != NULL)
 		log->head->refcount--;
-		mail_transaction_logs_clean(log);
-	}
+	mail_transaction_logs_clean(log);
+	i_assert(log->tail == NULL);
 
 	*_log = NULL;
 	log->index->log = NULL;
@@ -1004,9 +1004,9 @@
 	}
 
 	if (fstat(fd, &st) < 0) {
+		close_keep_errno(fd);
                 if (errno == ESTALE) {
                         /* treat as "doesn't exist" */
-                        (void)close(fd);
                         return 0;
                 }
                 mail_index_file_set_syscall_error(log->index, path, "fstat()");
@@ -1026,6 +1026,8 @@
 	ret = mail_transaction_log_file_fd_open(log, &file, path, fd,
 						FALSE, TRUE);
 	if (ret <= 0) {
+		bool stale = errno == ESTALE;
+
 		if (ret == 0) {
 			/* corrupted, delete it */
 			if (unlink(file->filepath) < 0 && errno != ENOENT) {
@@ -1035,7 +1037,9 @@
 			mail_transaction_log_file_free(file);
 			return 0;
                 }
-                if (errno == ESTALE) {
+		mail_transaction_log_file_free(file);
+
+		if (stale) {
                         /* treat as "doesn't exist" */
                         return 0;
                 }



More information about the dovecot-cvs mailing list