Hi libevent devs,

My company has been using libevent 1.4.14b and evhttp for a minimal
http interface for some daemon processes (a simple queue, a simple
database, etc). I was tracking down some memory issues and found that
HTTP/1.1 requests without the "Connection: close" header, or HTTP/1.0
requests with keep-alive enabled, to a process which uses evhttp to
act as an http server, result in a memory leak if the last request
made over the connection before it's closed doesn't have "Connection:
close". This is rather common, for example if you use curl with
default options to make a request to the process. It also happens if a
connection is opened and closed without sending any requests at all.

My fix is really tiny, and I think elegant and logical:

diff -urp libevent-1.4.14b-stable/http.c libevent-1.4.14b-stable-fix/http.c
--- libevent-1.4.14b-stable/http.c      2010-06-20 09:06:04.000000000 -0400
+++ libevent-1.4.14b-stable-fix/http.c  2012-05-09 14:51:37.000000000 -0400
@@ -2231,6 +2231,7 @@ evhttp_handle_request(struct evhttp_requ
        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__));

this prevents evhttp_connection_incoming_fail() from leaking the
evhttp_request, which it seemingly intentionally does for reasons I
don't fully understand. But I'm pretty sure that when the client
disconnects, they're done, and the request should go away when the
connection is freed, after the callbacks.

I don't know if libevent-1.4 fixes are no longer accepted, but we
would love it if  this was applied to the 1.4 branch and a new bugfix
release of the 1.4 branch was eventually made.

Thanks,
- Pierce
***********************************************************************
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-users    in the body.

Reply via email to