[dovecot-cvs] dovecot/src/lib-index mail-transaction-log-private.h, 1.13, 1.14 mail-transaction-log.c, 1.112, 1.113

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


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

Modified Files:
	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.14
diff -u -d -r1.13 -r1.14
--- mail-transaction-log-private.h	13 Jan 2006 20:26:13 -0000	1.13
+++ mail-transaction-log-private.h	8 Nov 2006 17:04:00 -0000	1.14
@@ -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.112
retrieving revision 1.113
diff -u -d -r1.112 -r1.113
--- mail-transaction-log.c	17 Jun 2006 13:42:37 -0000	1.112
+++ mail-transaction-log.c	8 Nov 2006 17:04:01 -0000	1.113
@@ -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