[dovecot-cvs] dovecot/src/lib-index mail-index-lock.c, 1.24, 1.25 mail-index.c, 1.141, 1.142

cras at dovecot.org cras at dovecot.org
Sat Jul 31 07:14:04 EEST 2004


Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv10269/lib-index

Modified Files:
	mail-index-lock.c mail-index.c 
Log Message:
Fixed fd leaks



Index: mail-index-lock.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-lock.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- mail-index-lock.c	8 Jul 2004 18:57:17 -0000	1.24
+++ mail-index-lock.c	31 Jul 2004 04:14:01 -0000	1.25
@@ -180,8 +180,11 @@
 		return -1;
 
 	if (index->lock_type == F_UNLCK) {
-		if (mail_index_lock_mprotect(index, F_RDLCK) < 0)
+		if (mail_index_lock_mprotect(index, F_RDLCK) < 0) {
+			(void)close(fd);
+			(void)unlink(path);
 			return -1;
+		}
 	}
 
 	ret = write_full(fd, index->map->hdr, sizeof(*index->map->hdr));
@@ -226,6 +229,7 @@
 
 	if (mail_index_reopen(index, fd) < 0) {
 		i_assert(index->excl_lock_count == 1);
+		(void)close(fd);
 		if (unlink(index->copy_lock_path) < 0) {
 			mail_index_file_set_syscall_error(index,
 							  index->copy_lock_path,
@@ -301,6 +305,8 @@
 
 static void mail_index_excl_unlock_finish(struct mail_index *index)
 {
+	int fd;
+
 	if (index->map != NULL && index->map->write_to_disk) {
 		i_assert(index->log_locked);
 
@@ -311,8 +317,11 @@
 			i_free(index->copy_lock_path);
 			index->copy_lock_path = NULL;
 		}
-		if (mail_index_copy(index) < 0)
+		fd = mail_index_copy(index);
+		if (fd == -1)
 			mail_index_set_inconsistent(index);
+		else
+			(void)close(fd);
 	}
 
 	if (index->copy_lock_path != NULL) {

Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- mail-index.c	31 Jul 2004 03:06:48 -0000	1.141
+++ mail-index.c	31 Jul 2004 04:14:01 -0000	1.142
@@ -491,8 +491,11 @@
 	if (ret <= 0)
 		return ret;
 
-	if (mail_index_lock_shared(index, FALSE, &lock_id) < 0)
+	if (mail_index_lock_shared(index, FALSE, &lock_id) < 0) {
+		(void)close(index->fd);
+		index->fd = -1;
 		return -1;
+	}
 	ret = mail_index_map(index, FALSE);
 	if (ret == 0) {
 		/* it's corrupted - recreate it */



More information about the dovecot-cvs mailing list