Skip to content

Commit

Permalink
global: Use fd_close_maybe_stdio()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Nov 16, 2016
1 parent 58bd950 commit d01fa63
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 23 deletions.
4 changes: 1 addition & 3 deletions src/imap-urlauth/imap-urlauth-client.c
Expand Up @@ -341,9 +341,7 @@ void client_destroy(struct client *client, const char *reason)

o_stream_destroy(&client->output);

net_disconnect(client->fd_in);
if (client->fd_in != client->fd_out)
net_disconnect(client->fd_out);
fd_close_maybe_stdio(&client->fd_in, &client->fd_out);

if (client->username != NULL)
i_free(client->username);
Expand Down
5 changes: 1 addition & 4 deletions src/imap-urlauth/imap-urlauth-worker.c
Expand Up @@ -255,10 +255,7 @@ static void client_destroy(struct client *client)
if (client->ctrl_output != NULL)
o_stream_destroy(&client->ctrl_output);

if (client->fd_in >= 0)
net_disconnect(client->fd_in);
if (client->fd_out >= 0 && client->fd_in != client->fd_out)
net_disconnect(client->fd_out);
fd_close_maybe_stdio(&client->fd_in, &client->fd_out);
if (client->fd_ctrl >= 0)
net_disconnect(client->fd_ctrl);

Expand Down
4 changes: 1 addition & 3 deletions src/imap/imap-client.c
Expand Up @@ -400,9 +400,7 @@ static void client_default_destroy(struct client *client, const char *reason)
timeout_remove(&client->to_idle);

/* i/ostreams are already closed at this stage, so fd can be closed */
net_disconnect(client->fd_in);
if (client->fd_in != client->fd_out)
net_disconnect(client->fd_out);
fd_close_maybe_stdio(&client->fd_in, &client->fd_out);

/* Free the user after client is already disconnected. It may start
some background work like autoexpunging. */
Expand Down
8 changes: 1 addition & 7 deletions src/lib/connection.c
Expand Up @@ -308,13 +308,7 @@ void connection_disconnect(struct connection *conn)
o_stream_close(conn->output);
o_stream_destroy(&conn->output);
}
if (conn->fd_in != -1) {
if (close(conn->fd_in) < 0)
i_error("close(%s) failed: %m", conn->name);
if (conn->fd_in != conn->fd_out && close(conn->fd_out) < 0)
i_error("close(%s/out) failed: %m", conn->name);
conn->fd_in = conn->fd_out = -1;
}
fd_close_maybe_stdio(&conn->fd_in, &conn->fd_out);
}

void connection_deinit(struct connection *conn)
Expand Down
4 changes: 1 addition & 3 deletions src/lmtp/client.c
Expand Up @@ -301,9 +301,7 @@ void client_destroy(struct client *client, const char *prefix,
i_stream_destroy(&client->input);
o_stream_destroy(&client->output);

net_disconnect(client->fd_in);
if (client->fd_in != client->fd_out)
net_disconnect(client->fd_out);
fd_close_maybe_stdio(&client->fd_in, &client->fd_out);
client_state_reset(client, "destroyed");
i_free(client->lhlo);
pool_unref(&client->state_pool);
Expand Down
4 changes: 1 addition & 3 deletions src/pop3/pop3-client.c
Expand Up @@ -642,9 +642,7 @@ static void client_default_destroy(struct client *client, const char *reason)
i_stream_destroy(&client->input);
o_stream_destroy(&client->output);

net_disconnect(client->fd_in);
if (client->fd_in != client->fd_out)
net_disconnect(client->fd_out);
fd_close_maybe_stdio(&client->fd_in, &client->fd_out);
mail_storage_service_user_free(&client->service_user);

pop3_client_count--;
Expand Down

0 comments on commit d01fa63

Please sign in to comment.