changeset 13093:3fff8093ab5b

sdbox: Avoid using too many fds when copying messages. This happened at least with quota plugin.
author Timo Sirainen <tss@iki.fi>
date Wed, 16 May 2012 18:57:05 +0300
parents 5830e7292909
children a13f0750a473
files src/lib-storage/index/dbox-single/sdbox-save.c
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-single/sdbox-save.c	Wed Apr 25 02:50:47 2012 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-save.c	Wed May 16 18:57:05 2012 +0300
@@ -78,9 +78,18 @@
 void sdbox_save_add_file(struct mail_save_context *_ctx, struct dbox_file *file)
 {
 	struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+	struct dbox_file *const *files;
+	unsigned int count;
 
 	if (ctx->first_saved_seq == 0)
 		ctx->first_saved_seq = ctx->ctx.seq;
+
+	files = array_get(&ctx->files, &count);
+	if (count > 0) {
+		/* a plugin may leave a previously saved file open.
+		   we'll close it here to avoid eating too many fds. */
+		dbox_file_close(files[count-1]);
+	}
 	array_append(&ctx->files, &file, 1);
 }