From: Josef 'Jeff' Sipek Date: Tue, 6 Jun 2017 07:20:49 +0000 (+0300) Subject: global: start relying on i_close_fd(-1) being a no-op X-Git-Tag: 2.3.0.rc1~988 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b032348d7bbb93ff96188289d3dfc1899b9abb3;p=thirdparty%2Fdovecot%2Fcore.git global: start relying on i_close_fd(-1) being a no-op Cleanup performed with the following semantic patch: @@ expression E; @@ - if (E != -1) - i_close_fd(&E); + i_close_fd(&E); --- diff --git a/src/doveadm/doveadm-dsync.c b/src/doveadm/doveadm-dsync.c index 3b8d4549ad..3235e65dad 100644 --- a/src/doveadm/doveadm-dsync.c +++ b/src/doveadm/doveadm-dsync.c @@ -735,8 +735,7 @@ cmd_dsync_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) } if (ctx->io_err != NULL) io_remove(&ctx->io_err); - if (ctx->fd_err != -1) - i_close_fd(&ctx->fd_err); + i_close_fd(&ctx->fd_err); if (ctx->child_wait != NULL) child_wait_free(&ctx->child_wait); diff --git a/src/imap-hibernate/imap-client.c b/src/imap-hibernate/imap-client.c index 3c7e11fd4a..6b770ba3fc 100644 --- a/src/imap-hibernate/imap-client.c +++ b/src/imap-hibernate/imap-client.c @@ -594,8 +594,7 @@ static void imap_client_stop(struct imap_client *client) array_foreach_modifiable(&client->notifys, notify) { if (notify->io != NULL) io_remove(¬ify->io); - if (notify->fd != -1) - i_close_fd(¬ify->fd); + i_close_fd(¬ify->fd); } } diff --git a/src/imap-hibernate/imap-hibernate-client.c b/src/imap-hibernate/imap-hibernate-client.c index 545beb4544..d9c65e5e78 100644 --- a/src/imap-hibernate/imap-hibernate-client.c +++ b/src/imap-hibernate/imap-hibernate-client.c @@ -232,8 +232,7 @@ imap_hibernate_client_input_line(struct connection *conn, const char *line) if (ret < 0) { if (client->imap_client != NULL) imap_client_destroy(&client->imap_client, NULL); - if (fd != -1) - i_close_fd(&fd); + i_close_fd(&fd); return -1; } else if (ret == 0) { /* still need to read another fd */ diff --git a/src/imap/imap-client-hibernate.c b/src/imap/imap-client-hibernate.c index 1ebe7fb4f8..bc63e8c66f 100644 --- a/src/imap/imap-client-hibernate.c +++ b/src/imap/imap-client-hibernate.c @@ -233,8 +233,7 @@ bool imap_client_hibernate(struct client **_client) if (imap_hibernate_process_send(client, state, fd_notify, &fd_hibernate) < 0) ret = -1; } - if (fd_notify != -1) - i_close_fd(&fd_notify); + i_close_fd(&fd_notify); if (ret > 0) { /* hide the disconnect log message, because the client didn't actually log out */ diff --git a/src/lib-dict/dict-file.c b/src/lib-dict/dict-file.c index 777edb131a..a35a9c480e 100644 --- a/src/lib-dict/dict-file.c +++ b/src/lib-dict/dict-file.c @@ -623,8 +623,7 @@ file_dict_write_changes(struct dict_transaction_memory_context *ctx, file_lock_free(&lock); } - if (dict->fd != -1) - i_close_fd(&dict->fd); + i_close_fd(&dict->fd); dict->fd = fd; return 0; } diff --git a/src/lib-http/test-http-client-errors.c b/src/lib-http/test-http-client-errors.c index 0f29bcd5e9..15bc4f78b5 100644 --- a/src/lib-http/test-http-client-errors.c +++ b/src/lib-http/test-http-client-errors.c @@ -3144,8 +3144,7 @@ static void test_run_client_server( ioloop = io_loop_create(); server_test(i); io_loop_destroy(&ioloop); - if (fd_listen != -1) - i_close_fd(&fd_listen); + i_close_fd(&fd_listen); i_free(bind_ports); i_free(server_pids); /* wait for it to be killed; this way, valgrind will not @@ -3153,8 +3152,7 @@ static void test_run_client_server( sleep(60); exit(1); } - if (fd_listen != -1) - i_close_fd(&fd_listen); + i_close_fd(&fd_listen); } if (debug) i_debug("client: PID=%s", my_pid); @@ -3181,15 +3179,13 @@ static void test_run_client_server( ioloop = io_loop_create(); dns_test(); io_loop_destroy(&ioloop); - if (fd_listen != -1) - i_close_fd(&fd_listen); + i_close_fd(&fd_listen); /* wait for it to be killed; this way, valgrind will not object to this process going away inelegantly. */ sleep(60); exit(1); } - if (fd_listen != -1) - i_close_fd(&fd_listen); + i_close_fd(&fd_listen); } /* parent: client */ diff --git a/src/lib-http/test-http-payload.c b/src/lib-http/test-http-payload.c index e24274ee33..4a67606ab8 100644 --- a/src/lib-http/test-http-payload.c +++ b/src/lib-http/test-http-payload.c @@ -1226,8 +1226,7 @@ static void test_client_deinit(void) static void test_open_server_fd(void) { - if (fd_listen != -1) - i_close_fd(&fd_listen); + i_close_fd(&fd_listen); fd_listen = net_listen(&bind_ip, &bind_port, 128); if (fd_listen == -1) { i_fatal("listen(%s:%u) failed: %m", diff --git a/src/lib-imap-client/test-imapc-client.c b/src/lib-imap-client/test-imapc-client.c index b2f405b517..261469e6ff 100644 --- a/src/lib-imap-client/test-imapc-client.c +++ b/src/lib-imap-client/test-imapc-client.c @@ -91,8 +91,7 @@ static void test_server_disconnect(struct test_server *server) i_stream_unref(&server->input); if (server->output != NULL) o_stream_unref(&server->output); - if (server->fd != -1) - i_close_fd(&server->fd); + i_close_fd(&server->fd); } static void test_server_disconnect_and_wait(bool send_banner) @@ -166,8 +165,7 @@ static void test_run_client_server( imapc_client_deinit(&imapc_client); io_loop_destroy(&ioloop); - if (server.fd_listen != -1) - i_close_fd(&server.fd_listen); + i_close_fd(&server.fd_listen); test_server_kill(); if (unlink_directory(client_set->temp_path_prefix, UNLINK_DIRECTORY_FLAG_RMDIR, &error) < 0) diff --git a/src/lib-mail/istream-attachment-extractor.c b/src/lib-mail/istream-attachment-extractor.c index a1ea7f136f..f341159112 100644 --- a/src/lib-mail/istream-attachment-extractor.c +++ b/src/lib-mail/istream-attachment-extractor.c @@ -535,8 +535,7 @@ static void astream_part_reset(struct attachment_istream *astream) if (part->temp_output != NULL) o_stream_destroy(&part->temp_output); - if (part->temp_fd != -1) - i_close_fd(&part->temp_fd); + i_close_fd(&part->temp_fd); i_free_and_null(part->content_type); i_free_and_null(part->content_disposition); diff --git a/src/lib/iostream-temp.c b/src/lib/iostream-temp.c index 274764fb72..1e63d97b57 100644 --- a/src/lib/iostream-temp.c +++ b/src/lib/iostream-temp.c @@ -39,8 +39,7 @@ o_stream_temp_close(struct iostream_private *stream, { struct temp_ostream *tstream = (struct temp_ostream *)stream; - if (tstream->fd != -1) - i_close_fd(&tstream->fd); + i_close_fd(&tstream->fd); if (tstream->buf != NULL) buffer_free(&tstream->buf); i_free(tstream->temp_path_prefix); diff --git a/src/lib/istream-unix.c b/src/lib/istream-unix.c index c9f4149d27..3d79bedf9c 100644 --- a/src/lib/istream-unix.c +++ b/src/lib/istream-unix.c @@ -16,8 +16,7 @@ i_stream_unix_close(struct iostream_private *stream, bool close_parent) { struct unix_istream *ustream = (struct unix_istream *)stream; - if (ustream->read_fd != -1) - i_close_fd(&ustream->read_fd); + i_close_fd(&ustream->read_fd); i_stream_file_close(stream, close_parent); } diff --git a/src/lib/net.c b/src/lib/net.c index ebef1cdbe8..df35e4c902 100644 --- a/src/lib/net.c +++ b/src/lib/net.c @@ -547,7 +547,7 @@ int net_listen_unix_unlink_stale(const char *path, int backlog) /* see if it really exists */ fd = net_connect_unix(path); if (fd != -1 || errno != ECONNREFUSED) { - if (fd != -1) i_close_fd(&fd); + i_close_fd(&fd); errno = EADDRINUSE; return -1; } diff --git a/src/lib/ostream-unix.c b/src/lib/ostream-unix.c index cfe87a6278..990a05685b 100644 --- a/src/lib/ostream-unix.c +++ b/src/lib/ostream-unix.c @@ -15,8 +15,7 @@ o_stream_unix_close(struct iostream_private *stream, bool close_parent) { struct unix_ostream *ustream = (struct unix_ostream *)stream; - if (ustream->write_fd != -1) - i_close_fd(&ustream->write_fd); + i_close_fd(&ustream->write_fd); o_stream_file_close(stream, close_parent); } diff --git a/src/master/service-listen.c b/src/master/service-listen.c index 2e7917fe60..036dedcbec 100644 --- a/src/master/service-listen.c +++ b/src/master/service-listen.c @@ -81,8 +81,7 @@ static int service_unix_listener_listen(struct service_listener *l) after 3 times just fail here. */ fd = net_connect_unix(set->path); if (fd != -1 || errno != ECONNREFUSED || i >= 3) { - if (fd != -1) - i_close_fd(&fd); + i_close_fd(&fd); service_error(service, "Socket already exists: %s", set->path); return 0; diff --git a/src/master/service-monitor.c b/src/master/service-monitor.c index 9eddaff059..058e8f3d14 100644 --- a/src/master/service-monitor.c +++ b/src/master/service-monitor.c @@ -566,8 +566,7 @@ void service_monitor_stop_close(struct service *service) array_foreach(&service->listeners, listeners) { struct service_listener *l = *listeners; - if (l->fd != -1) - i_close_fd(&l->fd); + i_close_fd(&l->fd); } } @@ -659,8 +658,7 @@ void services_monitor_stop(struct service_list *service_list, bool wait) if (service_list->io_master != NULL) io_remove(&service_list->io_master); - if (service_list->master_fd != -1) - i_close_fd(&service_list->master_fd); + i_close_fd(&service_list->master_fd); array_foreach(&service_list->services, services) service_monitor_stop(*services); diff --git a/src/plugins/fts-lucene/fts-backend-lucene.c b/src/plugins/fts-lucene/fts-backend-lucene.c index bc501547b1..e839838b10 100644 --- a/src/plugins/fts-lucene/fts-backend-lucene.c +++ b/src/plugins/fts-lucene/fts-backend-lucene.c @@ -289,8 +289,7 @@ fts_backend_lucene_update_deinit(struct fts_backend_update_context *_ctx) str_tabescape(user->username), str_tabescape(ctx->first_box_vname)); fd = fts_indexer_cmd(user, cmd, &path); - if (fd != -1) - i_close_fd(&fd); + i_close_fd(&fd); } } diff --git a/src/plugins/fts/fts-expunge-log.c b/src/plugins/fts/fts-expunge-log.c index 4dbd895eae..56f9cb915c 100644 --- a/src/plugins/fts/fts-expunge-log.c +++ b/src/plugins/fts/fts-expunge-log.c @@ -79,8 +79,7 @@ void fts_expunge_log_deinit(struct fts_expunge_log **_log) struct fts_expunge_log *log = *_log; *_log = NULL; - if (log->fd != -1) - i_close_fd(&log->fd); + i_close_fd(&log->fd); i_free(log->path); i_free(log); } diff --git a/src/plugins/quota/quota-maildir.c b/src/plugins/quota/quota-maildir.c index a208396535..37b404f748 100644 --- a/src/plugins/quota/quota-maildir.c +++ b/src/plugins/quota/quota-maildir.c @@ -771,8 +771,7 @@ static void maildir_quota_deinit(struct quota_root *_root) { struct maildir_quota_root *root = (struct maildir_quota_root *)_root; - if (root->fd != -1) - i_close_fd(&root->fd); + i_close_fd(&root->fd); i_free(root); } @@ -888,8 +887,7 @@ maildir_quota_update(struct quota_root *_root, i_close_fd(&root->fd); (void)maildirsize_recalculate(root); } else if (maildirsize_update(root, ctx->count_used, ctx->bytes_used) < 0) { - if (root->fd != -1) - i_close_fd(&root->fd); + i_close_fd(&root->fd); maildirsize_rebuild_later(root); } diff --git a/src/plugins/stats/mail-stats-fill.c b/src/plugins/stats/mail-stats-fill.c index d706450d34..47c52cf1d2 100644 --- a/src/plugins/stats/mail-stats-fill.c +++ b/src/plugins/stats/mail-stats-fill.c @@ -144,6 +144,5 @@ void mail_stats_fill(struct stats_user *suser, struct mail_stats *stats_r) void mail_stats_fill_global_deinit(void) { - if (proc_io_fd != -1) - i_close_fd(&proc_io_fd); + i_close_fd(&proc_io_fd); } diff --git a/src/stats/stats-carbon.c b/src/stats/stats-carbon.c index 1fb81812dc..7cc276cd1f 100644 --- a/src/stats/stats-carbon.c +++ b/src/stats/stats-carbon.c @@ -37,8 +37,7 @@ stats_carbon_destroy(struct stats_send_ctx **_ctx) io_remove(&ctx->io); if (ctx->to != NULL) timeout_remove(&ctx->to); - if (ctx->fd != -1) - i_close_fd(&ctx->fd); + i_close_fd(&ctx->fd); pool_unref(&ctx->pool); }