dovecot-2.0: mdbox: Avoid leaking fds when saving many messages ...

dovecot at dovecot.org dovecot at dovecot.org
Sun Mar 6 23:55:13 EET 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/d1f30e375f40
changeset: 12659:d1f30e375f40
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Mar 06 23:55:01 2011 +0200
description:
mdbox: Avoid leaking fds when saving many messages larger than mdbox_rotate_size.

diffstat:

 src/lib-storage/index/dbox-multi/mdbox-map.c |  19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diffs (36 lines):

diff -r b44ec48d9425 -r d1f30e375f40 src/lib-storage/index/dbox-multi/mdbox-map.c
--- a/src/lib-storage/index/dbox-multi/mdbox-map.c	Sat Mar 05 13:36:19 2011 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-map.c	Sun Mar 06 23:55:01 2011 +0200
@@ -1095,6 +1095,23 @@
 	return 0;
 }
 
+static void
+mdbox_map_append_close_if_unneeded(struct mdbox_map *map,
+				   struct dbox_file_append_context *append_ctx)
+{
+	struct mdbox_file *mfile =
+		(struct mdbox_file *)append_ctx->file;
+	uoff_t end_offset = append_ctx->output->offset;
+
+	/* if this file is now large enough not to fit any other
+	   mails and we created it, close its fd since it's not
+	   needed anymore. */
+	if (end_offset > map->set->mdbox_rotate_size &&
+	    mfile->file_id == 0 &&
+	    dbox_file_append_flush(append_ctx) == 0)
+		dbox_file_close(append_ctx->file);
+}
+
 void mdbox_map_append_finish(struct mdbox_map_append_context *ctx)
 {
 	struct mdbox_map_append *appends, *last;
@@ -1110,6 +1127,8 @@
 	i_assert(cur_offset >= last->offset);
 	last->size = cur_offset - last->offset;
 	dbox_file_append_checkpoint(last->file_append);
+
+	mdbox_map_append_close_if_unneeded(ctx->map, last->file_append);
 }
 
 void mdbox_map_append_abort(struct mdbox_map_append_context *ctx)


More information about the dovecot-cvs mailing list