From 331d2de16c64fc40d7df16c2f955e8a381415673 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Mon, 22 Feb 2016 20:03:44 +0200 Subject: [PATCH] doveadm-http: Close client input correctly --- src/doveadm/client-connection-http.c | 11 ++++++----- src/doveadm/client-connection.c | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/doveadm/client-connection-http.c b/src/doveadm/client-connection-http.c index 3788d7a679..9f4f1bda93 100644 --- a/src/doveadm/client-connection-http.c +++ b/src/doveadm/client-connection-http.c @@ -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)); @@ -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"); @@ -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,"]"); diff --git a/src/doveadm/client-connection.c b/src/doveadm/client-connection.c index fda95496e2..3797f6adda 100644 --- a/src/doveadm/client-connection.c +++ b/src/doveadm/client-connection.c @@ -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);