]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: start relying on i_close_fd(-1) being a no-op
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Tue, 6 Jun 2017 07:20:49 +0000 (10:20 +0300)
committerJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Wed, 20 Sep 2017 09:29:06 +0000 (12:29 +0300)
Cleanup performed with the following semantic patch:

@@
expression E;
@@

- if (E != -1)
-  i_close_fd(&E);
+ i_close_fd(&E);

20 files changed:
src/doveadm/doveadm-dsync.c
src/imap-hibernate/imap-client.c
src/imap-hibernate/imap-hibernate-client.c
src/imap/imap-client-hibernate.c
src/lib-dict/dict-file.c
src/lib-http/test-http-client-errors.c
src/lib-http/test-http-payload.c
src/lib-imap-client/test-imapc-client.c
src/lib-mail/istream-attachment-extractor.c
src/lib/iostream-temp.c
src/lib/istream-unix.c
src/lib/net.c
src/lib/ostream-unix.c
src/master/service-listen.c
src/master/service-monitor.c
src/plugins/fts-lucene/fts-backend-lucene.c
src/plugins/fts/fts-expunge-log.c
src/plugins/quota/quota-maildir.c
src/plugins/stats/mail-stats-fill.c
src/stats/stats-carbon.c

index 3b8d4549ad98e34d8f48f372e6d2847aa21f1f15..3235e65dadf2b8b1b583ba7d035385d59b6fe9c0 100644 (file)
@@ -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);
index 3c7e11fd4aaf1fa4e9a1d82f4dd7482d97e0aaa3..6b770ba3fc0549ffa7829657c87b6c32860bb208 100644 (file)
@@ -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(&notify->io);
-               if (notify->fd != -1)
-                       i_close_fd(&notify->fd);
+               i_close_fd(&notify->fd);
        }
 }
 
index 545beb4544134d1013c2ee490134d9e42a2999ab..d9c65e5e78e556b7a268908d828bdeae78659b67 100644 (file)
@@ -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 */
index 1ebe7fb4f873ade7cda8b0a9013b2092dc49e0c2..bc63e8c66f9a826e42bafc0fecfa7c73736ed0de 100644 (file)
@@ -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 */
index 777edb131a42dfb953bca10f590afb0249b21b33..a35a9c480e831bec906ea7030665a70250fffbe5 100644 (file)
@@ -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;
 }
index 0f29bcd5e97105efec146c180ae617f0cea5368c..15bc4f78b5beb747166f41915ebc7534d2424383 100644 (file)
@@ -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 */
index e24274ee33081138519ffb2f6864702e76d6e621..4a67606ab85d6efcf6ac57710695702c41beccdc 100644 (file)
@@ -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",
index b2f405b517e75e62a24e8398f3075cc450d2d172..261469e6ff2260f745c96f39be307995b87fcacb 100644 (file)
@@ -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)
index a1ea7f136f9438f674fbe269bbee40d0ecce3134..f34115911295313092444b7ac31a89a781129bf0 100644 (file)
@@ -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);
index 274764fb7257dd2e8d73250033ed6a5a88a0c34f..1e63d97b57e4f016f73c15dedeff9d4fed862af0 100644 (file)
@@ -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);
index c9f4149d27f9502844ac32e5973082963025a6b4..3d79bedf9c6cd9c4554807fdd500c4bbb4d2d4b3 100644 (file)
@@ -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);
 }
 
index ebef1cdbe88d05a4d53cc9520470b9fcef6ebdb4..df35e4c9028384d0c7c57fdaaa1fd84f6e4af29b 100644 (file)
@@ -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;
                }
index cfe87a62780c68f3dcdf1b9603a666faf342aba2..990a05685bc9774bec2116a51077cc655a07cc9a 100644 (file)
@@ -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);
 }
 
index 2e7917fe60fa2ce676984540ac51e1dc6461eb8b..036dedcbec2cb98771a61bfbb1606e76c1417e7a 100644 (file)
@@ -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;
index 9eddaff05992b650f0e17ccdafaf35f43ff47ec5..058e8f3d14470ec523b772639e0bc0683096fe83 100644 (file)
@@ -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);
index bc501547b1c379af5531414621e3e2206d1d5afd..e839838b100d1c8c63396489944a949db2556bb0 100644 (file)
@@ -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);
                }
        }
 
index 4dbd895eae13531b73c38f50be32a0ecd8256d72..56f9cb915ca4e602325bbf9755083f603a3a98ac 100644 (file)
@@ -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);
 }
index a20839653534c71faafb7c2987368e3f4217bcc8..37b404f748f9cfc60590efafd7286ee213bbad0e 100644 (file)
@@ -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);
        }
 
index d706450d34650286c7ae30331781e57b56994b66..47c52cf1d270f4d85ee033f3fd70701d8f0c7be9 100644 (file)
@@ -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);
 }
index 1fb81812dc7a1568a0cec4f5d6b34a668f5ce75a..7cc276cd1f5dc8982b23b034c97909bb7c2cce8c 100644 (file)
@@ -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);
 }