From: Timo Sirainen Date: Wed, 16 May 2012 15:57:05 +0000 (+0300) Subject: sdbox: Avoid using too many fds when copying messages. X-Git-Tag: 2.1.7~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b5818150ab6701eebd0cf35fc143dc5c7a71aa8;p=thirdparty%2Fdovecot%2Fcore.git sdbox: Avoid using too many fds when copying messages. This happened at least with quota plugin. --- diff --git a/src/lib-storage/index/dbox-single/sdbox-save.c b/src/lib-storage/index/dbox-single/sdbox-save.c index 1227ecf3a6..1a6099a86f 100644 --- a/src/lib-storage/index/dbox-single/sdbox-save.c +++ b/src/lib-storage/index/dbox-single/sdbox-save.c @@ -78,9 +78,18 @@ sdbox_save_alloc(struct mailbox_transaction_context *t) 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); }