# HG changeset patch # User Timo Sirainen # Date 1140948299 -7200 # Node ID 71b8faa84ec69618fd47c480f5f9a79b412e4b17 # Parent d6c15318e73020744f89ee6ca2dfcf8bf9da9f47 Added i_stream_destroy() and o_stream_destroy() and used them instead of *_stream_unref() where possible. Fixes at least one problem with io_remove() being called after socket was closed, which caused problems with epoll. diff -r d6c15318e730 -r 71b8faa84ec6 src/auth/auth-master-connection.c --- a/src/auth/auth-master-connection.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/auth/auth-master-connection.c Sun Feb 26 12:04:59 2006 +0200 @@ -272,9 +272,9 @@ conn->destroyed = TRUE; if (conn->input != NULL) - i_stream_unref(&conn->input); + i_stream_destroy(&conn->input); if (conn->output != NULL) - o_stream_unref(&conn->output); + o_stream_destroy(&conn->output); if (conn->io != NULL) io_remove(&conn->io); if (conn->fd != -1) { diff -r d6c15318e730 -r 71b8faa84ec6 src/auth/auth-worker-server.c --- a/src/auth/auth-worker-server.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/auth/auth-worker-server.c Sun Feb 26 12:04:59 2006 +0200 @@ -128,8 +128,8 @@ buffer_free(conn->requests); io_remove(&conn->io); - i_stream_unref(&conn->input); - o_stream_unref(&conn->output); + i_stream_destroy(&conn->input); + o_stream_destroy(&conn->output); if (close(conn->fd) < 0) i_error("close(auth worker) failed: %m"); diff -r d6c15318e730 -r 71b8faa84ec6 src/auth/db-passwd-file.c --- a/src/auth/db-passwd-file.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/auth/db-passwd-file.c Sun Feb 26 12:04:59 2006 +0200 @@ -189,7 +189,7 @@ } t_pop(); } - i_stream_unref(&input); + i_stream_destroy(&input); if (pw->db->debug) { i_info("passwd-file %s: Read %u users", diff -r d6c15318e730 -r 71b8faa84ec6 src/deliver/deliver.c --- a/src/deliver/deliver.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/deliver/deliver.c Sun Feb 26 12:04:59 2006 +0200 @@ -130,8 +130,8 @@ io_loop_stop(ioloop); io_remove(conn->io); - i_stream_unref(conn->input); - o_stream_unref(conn->output); + i_stream_destroy(conn->input); + o_stream_destroy(conn->output); if (close(conn->fd) < 0) i_error("close() failed: %m"); i_free(conn); diff -r d6c15318e730 -r 71b8faa84ec6 src/dict/dict-server.c --- a/src/dict/dict-server.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/dict/dict-server.c Sun Feb 26 12:04:59 2006 +0200 @@ -369,8 +369,8 @@ } io_remove(&conn->io); - i_stream_unref(&conn->input); - o_stream_unref(&conn->output); + i_stream_destroy(&conn->input); + o_stream_destroy(&conn->output); if (close(conn->fd) < 0) i_error("close(dict client) failed: %m"); diff -r d6c15318e730 -r 71b8faa84ec6 src/imap/client.c --- a/src/imap/client.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/imap/client.c Sun Feb 26 12:04:59 2006 +0200 @@ -86,8 +86,8 @@ if (client->io != NULL) io_remove(&client->io); - i_stream_unref(&client->input); - o_stream_unref(&client->output); + i_stream_destroy(&client->input); + o_stream_destroy(&client->output); if (close(client->fd_in) < 0) i_error("close(client in) failed: %m"); diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-dict/dict-client.c --- a/src/lib-dict/dict-client.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-dict/dict-client.c Sun Feb 26 12:04:59 2006 +0200 @@ -209,9 +209,9 @@ dict->handshaked = FALSE; if (dict->input != NULL) - i_stream_unref(&dict->input); + i_stream_destroy(&dict->input); if (dict->output != NULL) - o_stream_unref(&dict->output); + o_stream_destroy(&dict->output); if (dict->fd != -1) { if (close(dict->fd) < 0) diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-dict/dict-sql.c --- a/src/lib-dict/dict-sql.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-dict/dict-sql.c Sun Feb 26 12:04:59 2006 +0200 @@ -72,7 +72,7 @@ t_pop(); } - i_stream_unref(&input); + i_stream_destroy(&input); (void)close(fd); if (dict->connect_string == NULL) { diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-imap/imap-bodystructure.c --- a/src/lib-imap/imap-bodystructure.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-imap/imap-bodystructure.c Sun Feb 26 12:04:59 2006 +0200 @@ -685,6 +685,6 @@ i_error("Error parsing IMAP bodystructure: %s", bodystructure); imap_parser_destroy(&parser); - i_stream_unref(&input); + i_stream_destroy(&input); return ret; } diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-imap/imap-envelope.c --- a/src/lib-imap/imap-envelope.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-imap/imap-envelope.c Sun Feb 26 12:04:59 2006 +0200 @@ -397,6 +397,6 @@ } imap_parser_destroy(&parser); - i_stream_unref(&input); + i_stream_destroy(&input); return ret; } diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-index/mail-cache-compress.c --- a/src/lib-index/mail-cache-compress.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-index/mail-cache-compress.c Sun Feb 26 12:04:59 2006 +0200 @@ -216,7 +216,7 @@ errno = output->stream_errno; mail_cache_set_syscall_error(cache, "o_stream_flush()"); (void)mail_index_transaction_rollback(&t); - o_stream_unref(&output); + o_stream_destroy(&output); return -1; } @@ -225,7 +225,7 @@ (void)file_set_size(fd, MAIL_CACHE_INITIAL_SIZE); } - o_stream_unref(&output); + o_stream_destroy(&output); if (fdatasync(fd) < 0) { mail_cache_set_syscall_error(cache, "fdatasync()"); diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-mail/message-body-search.c --- a/src/lib-mail/message-body-search.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-mail/message-body-search.c Sun Feb 26 12:04:59 2006 +0200 @@ -346,7 +346,7 @@ pos -= data_size; } - i_stream_unref(&input); + i_stream_destroy(&input); if (ctx->translation != NULL) charset_to_utf8_end(&ctx->translation); diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-settings/settings.c --- a/src/lib-settings/settings.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-settings/settings.c Sun Feb 26 12:04:59 2006 +0200 @@ -223,7 +223,7 @@ } } - i_stream_unref(&input); + i_stream_destroy(&input); t_pop(); return errormsg == NULL; diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/dbox/dbox-file.c --- a/src/lib-storage/index/dbox/dbox-file.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-file.c Sun Feb 26 12:04:59 2006 +0200 @@ -46,7 +46,7 @@ } if (file->input != NULL) - i_stream_unref(&file->input); + i_stream_destroy(&file->input); if (file->fd != -1) { if (close(file->fd) < 0) i_error("close(dbox) failed: %m"); diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/dbox/dbox-sync-expunge.c --- a/src/lib-storage/index/dbox/dbox-sync-expunge.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-sync-expunge.c Sun Feb 26 12:04:59 2006 +0200 @@ -182,7 +182,7 @@ mbox->file->seeked_offset, full_size); bytes = o_stream_send_istream(output, input); - i_stream_unref(&input); + i_stream_destroy(&input); if (bytes < 0) { mail_storage_set_critical(STORAGE(mbox->storage), @@ -223,7 +223,7 @@ break; } } - o_stream_unref(&output); + o_stream_destroy(&output); if (ret < 0) { file_dotlock_delete(&dotlock); diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/dbox/dbox-uidlist.c --- a/src/lib-storage/index/dbox/dbox-uidlist.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-uidlist.c Sun Feb 26 12:04:59 2006 +0200 @@ -413,7 +413,7 @@ uidlist->mtime = -1; } - i_stream_unref(&input); + i_stream_destroy(&input); return ret; } @@ -537,7 +537,7 @@ "write(%s) failed: %m", uidlist->path); ret = -1; } - o_stream_unref(&output); + o_stream_destroy(&output); if (ret < 0) return -1; @@ -681,7 +681,7 @@ "write(%s) failed: %m", ctx->uidlist->path); ret = -1; } - o_stream_unref(&output); + o_stream_destroy(&output); if (ret < 0) return -1; diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/index-mail-headers.c --- a/src/lib-storage/index/index-mail-headers.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/index-mail-headers.c Sun Feb 26 12:04:59 2006 +0200 @@ -609,7 +609,7 @@ mail->data.seq, headers->idx, headers->count) > 0) { if (mail->data.filter_stream != NULL) - i_stream_unref(&mail->data.filter_stream); + i_stream_destroy(&mail->data.filter_stream); mail->data.filter_stream = i_stream_create_from_data(default_pool, str_data(dest), @@ -623,7 +623,7 @@ return NULL; if (mail->data.filter_stream != NULL) - i_stream_unref(&mail->data.filter_stream); + i_stream_destroy(&mail->data.filter_stream); index_mail_parse_header_init(mail, _headers); mail->data.filter_stream = diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/index-mail.c --- a/src/lib-storage/index/index-mail.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/index-mail.c Sun Feb 26 12:04:59 2006 +0200 @@ -748,9 +748,9 @@ static void index_mail_close(struct index_mail *mail) { if (mail->data.stream != NULL) - i_stream_unref(&mail->data.stream); + i_stream_destroy(&mail->data.stream); if (mail->data.filter_stream != NULL) - i_stream_unref(&mail->data.filter_stream); + i_stream_destroy(&mail->data.filter_stream); } int index_mail_set_seq(struct mail *_mail, uint32_t seq) diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/maildir/maildir-keywords.c --- a/src/lib-storage/index/maildir/maildir-keywords.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/maildir/maildir-keywords.c Sun Feb 26 12:04:59 2006 +0200 @@ -141,7 +141,7 @@ strp = array_idx_modifyable(&mk->list, idx); *strp = new_name; } - i_stream_unref(&input); + i_stream_destroy(&input); if (close(fd) < 0) { mail_storage_set_critical(STORAGE(mk->mbox->storage), diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/maildir/maildir-save.c --- a/src/lib-storage/index/maildir/maildir-save.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/maildir/maildir-save.c Sun Feb 26 12:04:59 2006 +0200 @@ -257,7 +257,7 @@ } output_errno = ctx->output->stream_errno; - o_stream_unref(&ctx->output); + o_stream_destroy(&ctx->output); /* FIXME: when saving multiple messages, we could get better performance if we left the fd open and fsync()ed it later */ diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/maildir/maildir-uidlist.c --- a/src/lib-storage/index/maildir/maildir-uidlist.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/maildir/maildir-uidlist.c Sun Feb 26 12:04:59 2006 +0200 @@ -338,7 +338,7 @@ *retry_r = TRUE; } - i_stream_unref(&input); + i_stream_destroy(&input); return ret; } diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/mbox/mbox-file.c --- a/src/lib-storage/index/mbox/mbox-file.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-file.c Sun Feb 26 12:04:59 2006 +0200 @@ -127,15 +127,14 @@ mbox_file_fix_atime(mbox); if (mbox->mbox_stream != NULL) - i_stream_unref(&mbox->mbox_stream); + i_stream_destroy(&mbox->mbox_stream); if (mbox->mbox_file_stream != NULL) { if (mbox->mbox_fd == -1) { /* read-only mbox stream */ i_assert(mbox->mbox_readonly); } else { - i_stream_close(mbox->mbox_file_stream); - i_stream_unref(&mbox->mbox_file_stream); + i_stream_destroy(&mbox->mbox_file_stream); } } } diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/mbox/mbox-save.c --- a/src/lib-storage/index/mbox/mbox-save.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-save.c Sun Feb 26 12:04:59 2006 +0200 @@ -528,9 +528,9 @@ } if (ctx->input != NULL) - i_stream_unref(&ctx->input); + i_stream_destroy(&ctx->input); if (ctx->body_output != NULL) - o_stream_unref(&ctx->body_output); + o_stream_destroy(&ctx->body_output); if (ctx->failed && ctx->mail_offset != (uoff_t)-1) { /* saving this mail failed - truncate back to beginning of it */ @@ -565,7 +565,7 @@ i_assert(ctx->body_output == NULL); if (ctx->output != NULL) - o_stream_unref(&ctx->output); + o_stream_destroy(&ctx->output); if (ctx->mail != NULL) index_mail_free(ctx->mail); str_free(&ctx->headers); diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/mbox/mbox-storage.c --- a/src/lib-storage/index/mbox/mbox-storage.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-storage.c Sun Feb 26 12:04:59 2006 +0200 @@ -1039,7 +1039,7 @@ mbox_file_close(mbox); if (mbox->mbox_file_stream != NULL) - i_stream_unref(&mbox->mbox_file_stream); + i_stream_destroy(&mbox->mbox_file_stream); index_storage_mailbox_free(box); return ret; diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/index/mbox/mbox-sync-rewrite.c --- a/src/lib-storage/index/mbox/mbox-sync-rewrite.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-sync-rewrite.c Sun Feb 26 12:04:59 2006 +0200 @@ -51,7 +51,7 @@ } i_stream_sync(sync_ctx->input); - o_stream_unref(&output); + o_stream_destroy(&output); return (int)ret; } diff -r d6c15318e730 -r 71b8faa84ec6 src/lib-storage/subscription-file/subscription-file.c --- a/src/lib-storage/subscription-file/subscription-file.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib-storage/subscription-file/subscription-file.c Sun Feb 26 12:04:59 2006 +0200 @@ -144,8 +144,8 @@ } if (input != NULL) - i_stream_unref(&input); - o_stream_unref(&output); + i_stream_destroy(&input); + o_stream_destroy(&output); if (failed || (set && found) || (!set && !found)) { if (file_dotlock_delete(&dotlock) < 0) { @@ -195,7 +195,7 @@ failed = ctx->failed; if (ctx->input != NULL) - i_stream_unref(&ctx->input); + i_stream_destroy(&ctx->input); pool_unref(ctx->pool); return failed ? -1 : 0; @@ -221,7 +221,7 @@ this isn't the optimal behavior, but it's allowed by IMAP and this way we don't have to read everything into memory or try to play any guessing games. */ - i_stream_unref(&ctx->input); + i_stream_destroy(&ctx->input); fd = safe_open(ctx->path, O_RDONLY); if (fd == -1) { diff -r d6c15318e730 -r 71b8faa84ec6 src/lib/istream.c --- a/src/lib/istream.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib/istream.c Sun Feb 26 12:04:59 2006 +0200 @@ -5,6 +5,12 @@ #include "str.h" #include "istream-internal.h" +void i_stream_destroy(struct istream **stream) +{ + i_stream_close(*stream); + i_stream_unref(stream); +} + void i_stream_ref(struct istream *stream) { _io_stream_ref(&stream->real_stream->iostream); diff -r d6c15318e730 -r 71b8faa84ec6 src/lib/istream.h --- a/src/lib/istream.h Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib/istream.h Sun Feb 26 12:04:59 2006 +0200 @@ -24,6 +24,9 @@ struct istream *i_stream_create_limit(pool_t pool, struct istream *input, uoff_t v_start_offset, uoff_t v_size); +/* i_stream_close() + i_stream_unref() */ +void i_stream_destroy(struct istream **stream); + /* Reference counting. References start from 1, so calling i_stream_unref() destroys the stream if i_stream_ref() is never used. */ void i_stream_ref(struct istream *stream); diff -r d6c15318e730 -r 71b8faa84ec6 src/lib/ostream.c --- a/src/lib/ostream.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib/ostream.c Sun Feb 26 12:04:59 2006 +0200 @@ -4,6 +4,12 @@ #include "istream.h" #include "ostream-internal.h" +void o_stream_destroy(struct ostream **stream) +{ + o_stream_close(*stream); + o_stream_unref(stream); +} + void o_stream_ref(struct ostream *stream) { _io_stream_ref(&stream->real_stream->iostream); diff -r d6c15318e730 -r 71b8faa84ec6 src/lib/ostream.h --- a/src/lib/ostream.h Sat Feb 25 13:29:05 2006 +0200 +++ b/src/lib/ostream.h Sun Feb 26 12:04:59 2006 +0200 @@ -27,6 +27,8 @@ o_stream_create_file(int fd, pool_t pool, size_t max_buffer_size, bool autoclose_fd); +/* o_stream_close() + o_stream_unref() */ +void o_stream_destroy(struct ostream **stream); /* Reference counting. References start from 1, so calling o_stream_unref() destroys the stream if o_stream_ref() is never used. */ void o_stream_ref(struct ostream *stream); diff -r d6c15318e730 -r 71b8faa84ec6 src/login-common/login-proxy.c --- a/src/login-common/login-proxy.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/login-common/login-proxy.c Sun Feb 26 12:04:59 2006 +0200 @@ -201,7 +201,7 @@ if (proxy->client_io != NULL) io_remove(&proxy->client_io); if (proxy->client_output != NULL) - o_stream_unref(&proxy->client_output); + o_stream_destroy(&proxy->client_output); net_disconnect(proxy->client_fd); } else { proxy->destroying = TRUE; @@ -211,9 +211,9 @@ if (proxy->server_io != NULL) io_remove(&proxy->server_io); if (proxy->server_input != NULL) - i_stream_unref(&proxy->server_input); + i_stream_destroy(&proxy->server_input); if (proxy->server_output != NULL) - o_stream_unref(&proxy->server_output); + o_stream_destroy(&proxy->server_output); net_disconnect(proxy->server_fd); i_free(proxy->host); diff -r d6c15318e730 -r 71b8faa84ec6 src/login-common/master.c --- a/src/login-common/master.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/login-common/master.c Sun Feb 26 12:04:59 2006 +0200 @@ -151,7 +151,7 @@ env_put(line); } while (line == NULL); - i_stream_unref(&input); + i_stream_destroy(&input); } int master_connect(const char *group_name) diff -r d6c15318e730 -r 71b8faa84ec6 src/master/auth-process.c --- a/src/master/auth-process.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/master/auth-process.c Sun Feb 26 12:04:59 2006 +0200 @@ -355,8 +355,8 @@ hash_iterate_deinit(iter); hash_destroy(p->requests); - i_stream_unref(&p->input); - o_stream_unref(&p->output); + i_stream_destroy(&p->input); + o_stream_destroy(&p->output); io_remove(&p->io); if (close(p->fd) < 0) i_error("close(auth) failed: %m"); diff -r d6c15318e730 -r 71b8faa84ec6 src/master/log.c --- a/src/master/log.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/master/log.c Sun Feb 26 12:04:59 2006 +0200 @@ -217,7 +217,7 @@ io_remove(&log_io->io); else throttle_count--; - i_stream_unref(&log_io->stream); + i_stream_destroy(&log_io->stream); i_free(log_io->prefix); i_free(log_io); } diff -r d6c15318e730 -r 71b8faa84ec6 src/plugins/trash/trash-plugin.c --- a/src/plugins/trash/trash-plugin.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/plugins/trash/trash-plugin.c Sun Feb 26 12:04:59 2006 +0200 @@ -260,7 +260,7 @@ trash->name = p_strdup(config_pool, name+1); trash->priority = atoi(t_strdup_until(line, name)); } - i_stream_unref(&input); + i_stream_destroy(&input); (void)close(fd); qsort(array_get_modifyable(&trash_boxes, NULL), diff -r d6c15318e730 -r 71b8faa84ec6 src/pop3/client.c --- a/src/pop3/client.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/pop3/client.c Sun Feb 26 12:04:59 2006 +0200 @@ -230,8 +230,8 @@ if (client->io != NULL) io_remove(&client->io); - i_stream_unref(&client->input); - o_stream_unref(&client->output); + i_stream_destroy(&client->input); + o_stream_destroy(&client->output); if (close(client->fd_in) < 0) i_error("close(client in) failed: %m"); diff -r d6c15318e730 -r 71b8faa84ec6 src/util/rawlog.c --- a/src/util/rawlog.c Sat Feb 25 13:29:05 2006 +0200 +++ b/src/util/rawlog.c Sun Feb 26 12:04:59 2006 +0200 @@ -52,9 +52,9 @@ if (proxy->server_io != NULL) io_remove(&proxy->server_io); - i_stream_unref(&proxy->server_input); - o_stream_unref(&proxy->client_output); - o_stream_unref(&proxy->server_output); + i_stream_destroy(&proxy->server_input); + o_stream_destroy(&proxy->client_output); + o_stream_destroy(&proxy->server_output); if (close(proxy->client_in_fd) < 0) i_error("close(client_in_fd) failed: %m");