commit 33ce983bb67fd94705247a9523c0881c68589107
parent 16f6b9460c6da8f32848bfdfd09cebf8f48d14b5
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Wed, 29 Sep 2021 20:35:19 +0300
transmit_error_response(): use last resort to send error response
Diffstat:
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -2293,15 +2293,35 @@ transmit_error_response_len (struct MHD_Connection *connection,
connection->keepalive = MHD_CONN_MUST_CLOSE;
if (MHD_NO == build_header_response (connection))
{
- /* oops - close! */
- CONNECTION_CLOSE_ERROR (connection,
- _ ("Closing connection " \
- "(failed to create error response header)."));
- }
- else
- {
- connection->state = MHD_CONNECTION_HEADERS_SENDING;
+ /* No memory. Release everything. */
+ connection->version = NULL;
+ connection->method = NULL;
+ connection->url = NULL;
+ connection->last = NULL;
+ connection->colon = NULL;
+ connection->headers_received = NULL;
+ connection->headers_received_tail = NULL;
+ connection->write_buffer = NULL;
+ connection->write_buffer_size = 0;
+ connection->write_buffer_send_offset = 0;
+ connection->write_buffer_append_offset = 0;
+ connection->read_buffer
+ = MHD_pool_reset (connection->pool,
+ NULL,
+ 0,
+ 0);
+ connection->read_buffer_size = 0;
+
+ /* Retry with empty buffer */
+ if (MHD_NO == build_header_response (connection))
+ {
+ CONNECTION_CLOSE_ERROR (connection,
+ _ ("Closing connection " \
+ "(failed to create error response header)."));
+ return;
+ }
}
+ connection->state = MHD_CONNECTION_HEADERS_SENDING;
}