From 46a1375b59c98f854a2bc629e0c8a1a6bed4434b Mon Sep 17 00:00:00 2001 From: Pierce Lopez Date: Wed, 28 Jan 2015 13:37:16 -0500 Subject: [PATCH] evhttp: fix leak from keep-alive disconnect or read/write timeout When a keep-alive HTTP/1.1 connection disconnects, or when there's a read or write timeout (default after 60 seconds), evhttp failed to free the connection context memory. --- http.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/http.c b/http.c index 4abce239..06ebf55d 100644 --- a/http.c +++ b/http.c @@ -695,9 +695,13 @@ void evhttp_write(int fd, short what, void *arg) { struct evhttp_connection *evcon = arg; + struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); int n; if (what == EV_TIMEOUT) { + if (req != NULL) { + req->userdone = 1; + } evhttp_connection_fail(evcon, EVCON_HTTP_TIMEOUT); return; } @@ -935,6 +939,7 @@ evhttp_read(int fd, short what, void *arg) int n, len; if (what == EV_TIMEOUT) { + req->userdone = 1; evhttp_connection_fail(evcon, EVCON_HTTP_TIMEOUT); return; } @@ -2239,6 +2244,7 @@ evhttp_handle_request(struct evhttp_request *req, void *arg) if (req->uri == NULL) { event_debug(("%s: bad request", __func__)); if (req->evcon->state == EVCON_DISCONNECTED) { + req->userdone = 1; evhttp_connection_fail(req->evcon, EVCON_HTTP_EOF); } else { event_debug(("%s: sending error", __func__));