diff options
-rw-r--r-- | spool2dir.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/spool2dir.c b/spool2dir.c index 59293d8..da17c5b 100644 --- a/spool2dir.c +++ b/spool2dir.c @@ -135,7 +135,7 @@ static int backend_handle_mail(struct mailbox_transaction_context *t, const char *dest, *buf; const unsigned char *beginning; size_t size; - int fd; + int fd = -1; i_assert(ast); @@ -171,13 +171,14 @@ static int backend_handle_mail(struct mailbox_transaction_context *t, while (ast->count <= 9999) { buf = t_strdup_printf(dest, (long)time(0), (long)++ast->count); fd = open(buf, O_CREAT | O_EXCL | O_WRONLY, 0600); - if(fd >= 0 || errno != EEXIST) + if (fd >= 0 || errno != EEXIST) break; /* current filename in buf already exists, zap it */ t_pop(); t_push(); - /* buf is invalid now ! */ + /* buf is invalid now! */ } + if (fd < 0) { debug("spool2dir backend: Failed to create spool file %s: %s\n", dest, strerror(errno)); @@ -188,6 +189,7 @@ static int backend_handle_mail(struct mailbox_transaction_context *t, } /* buf still points to allocated memory, because fd >= 0 */ + outstream = o_stream_create_from_fd(fd, t->box->pool); if (!outstream) { mail_storage_set_error(t->box->storage, @@ -221,10 +223,9 @@ static int backend_handle_mail(struct mailbox_transaction_context *t, o_stream_destroy(&outstream); out_close: close(fd); - out: if (ret) unlink(buf); - + out: t_pop(); return ret; |