dovecot-2.2: dbox: Close file's fd only after its istream is des...

dovecot at dovecot.org dovecot at dovecot.org
Tue Apr 23 20:51:47 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/6d19a0f32a1b
changeset: 16314:6d19a0f32a1b
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 23 20:51:34 2013 +0300
description:
dbox: Close file's fd only after its istream is destroyed.
For example zlib plugin keeps the stream open as a cache even after the
dbox_file has been destroyed.

diffstat:

 src/lib-storage/index/dbox-common/dbox-file.c |  9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 2784b88a4260 -r 6d19a0f32a1b src/lib-storage/index/dbox-common/dbox-file.c
--- a/src/lib-storage/index/dbox-common/dbox-file.c	Tue Apr 23 17:21:46 2013 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-file.c	Tue Apr 23 20:51:34 2013 +0300
@@ -215,7 +215,7 @@
 		}
 	}
 
-	file->input = i_stream_create_fd(file->fd, DBOX_READ_BLOCK_SIZE, FALSE);
+	file->input = i_stream_create_fd(file->fd, DBOX_READ_BLOCK_SIZE, TRUE);
 	i_stream_set_name(file->input, file->cur_path);
 	i_stream_set_init_buffer_size(file->input, DBOX_READ_BLOCK_SIZE);
 	return dbox_file_read_header(file);
@@ -286,9 +286,12 @@
 void dbox_file_close(struct dbox_file *file)
 {
 	dbox_file_unlock(file);
-	if (file->input != NULL)
+	if (file->input != NULL) {
+		/* stream autocloses the fd when it gets destroyed. note that
+		   the stream may outlive the struct dbox_file. */
 		i_stream_unref(&file->input);
-	if (file->fd != -1) {
+		file->fd = -1;
+	} else if (file->fd != -1) {
 		if (close(file->fd) < 0)
 			dbox_file_set_syscall_error(file, "close()");
 		file->fd = -1;


More information about the dovecot-cvs mailing list