diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2011-03-08 15:55:48 +0100 |
---|---|---|
committer | Johannes Berg <johannes@sipsolutions.net> | 2011-03-08 15:55:48 +0100 |
commit | 9ad6e48571bc99f5b629cdd2ecbf29ffe335ca7b (patch) | |
tree | 514043704d053920824dd8970eb116388822b977 | |
parent | 4e74951f612263f40c07459e8a9304904c4421f2 (diff) | |
download | dovecot-antispam-9ad6e48571bc99f5b629cdd2ecbf29ffe335ca7b.tar.gz dovecot-antispam-9ad6e48571bc99f5b629cdd2ecbf29ffe335ca7b.tar.xz dovecot-antispam-9ad6e48571bc99f5b629cdd2ecbf29ffe335ca7b.zip |
spool2dir: fix destination file loop
-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; |