]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
sdbox: Avoid using too many fds when copying messages.
authorTimo Sirainen <tss@iki.fi>
Wed, 16 May 2012 15:57:05 +0000 (18:57 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 16 May 2012 15:57:05 +0000 (18:57 +0300)
This happened at least with quota plugin.

src/lib-storage/index/dbox-single/sdbox-save.c

index 1227ecf3a6e1fef6cfa134ce6771d8961736bec1..1a6099a86fc10aebc2c5dc5b9e0658a8d1834ffb 100644 (file)
@@ -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);
 }