]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm-http: Close client input correctly
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 22 Feb 2016 18:03:44 +0000 (20:03 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 22 Feb 2016 18:03:44 +0000 (20:03 +0200)
src/doveadm/client-connection-http.c
src/doveadm/client-connection.c

index 3788d7a67993b08ee183301ae9034be60e0c0312..9f4f1bda93948540e410c1277cea9a9933cb798e 100644 (file)
@@ -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,"]");
 
index fda95496e29625ac35db3f34c56ad95430339da5..3797f6adda58226082aa79b131b594a216f0840f 100644 (file)
@@ -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);