Skip to content

Commit

Permalink
doveadm-http: Close client input correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse authored and sirainen committed Feb 22, 2016
1 parent 346ce9e commit 331d2de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/doveadm/client-connection-http.c
Expand Up @@ -132,6 +132,9 @@ doveadm_http_server_request_destroy(void *context)
(void)json_parser_deinit(&conn->json_parser, &error);
// we've already failed, ignore error
}
if (conn->client.output != NULL)
o_stream_set_no_error_handling(conn->client.output, TRUE);

http_server_request_unref(&(conn->http_server_request));
http_server_switch_ioloop(doveadm_http_server);
http_server_connection_unref(&(conn->http_client));
Expand Down Expand Up @@ -462,6 +465,9 @@ doveadm_http_server_read_request(struct client_connection_http *conn)
if (!conn->client.input->eof && rc == 0)
return;

io_remove(&conn->client.io);
conn->client.io = NULL;

if (rc == -2 || (rc == 1 && conn->json_state != JSON_STATE_DONE)) {
/* this will happen if the parser above runs into unexpected element, but JSON is OK */
http_server_request_fail_close(conn->http_server_request, 400, "Unexpected element in input");
Expand All @@ -488,11 +494,6 @@ doveadm_http_server_read_request(struct client_connection_http *conn)

conn->json_parser = NULL;

io_remove(&conn->client.io);
conn->client.io = NULL;
i_stream_unref(&conn->client.input);
conn->client.input = NULL;

if (conn->client.output != NULL)
o_stream_nsend_str(conn->client.output,"]");

Expand Down
5 changes: 4 additions & 1 deletion src/doveadm/client-connection.c
Expand Up @@ -570,10 +570,13 @@ void client_connection_destroy(struct client_connection **_conn)
o_stream_destroy(&conn->output);

if (conn->io != NULL) {
i_stream_destroy(&conn->input);
io_remove(&conn->io);
}

if (conn->input != NULL) {
i_stream_destroy(&conn->input);
}

if (conn->fd > 0 && close(conn->fd) < 0)
i_error("close(client) failed: %m");
pool_unref(&conn->pool);
Expand Down

0 comments on commit 331d2de

Please sign in to comment.