changeset 19730:5a31f0ae5b6f

lib-http: server: Fixed memory problem reported by Valgrind, which was caused by the request being freed too early while sending a response. Fixed by referencing the request while it is being sent.
author Stephan Bosch <stephan@rename-it.nl>
date Mon, 08 Feb 2016 22:52:38 +0100
parents 283300040a6e
children e7c075618c6d
files src/lib-http/http-server-connection.c
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-http/http-server-connection.c	Mon Feb 08 22:51:14 2016 +0100
+++ b/src/lib-http/http-server-connection.c	Mon Feb 08 22:52:38 2016 +0100
@@ -594,6 +594,7 @@
 {
 	struct http_server_request *req;
 	const char *error = NULL;
+	int ret;
 
 	if (conn->output_locked)
 		return FALSE;
@@ -645,7 +646,11 @@
 
 	http_server_connection_timeout_start(conn);
 
-	if (http_server_response_send(req->response, &error) < 0) {
+	http_server_request_ref(req);
+	ret = http_server_response_send(req->response, &error);
+	http_server_request_unref(&req);
+
+	if (ret < 0) {
 		if (error != NULL) {
 			http_server_connection_error(conn,
 				"Failed to send response: %s", error);