]> granicus.if.org Git - libevent/commitdiff
http: fix EVHTTP_CON_AUTOFREE in case of connection error
authorAzat Khuzhin <azat@libevent.org>
Mon, 18 May 2020 22:02:30 +0000 (01:02 +0300)
committerAzat Khuzhin <azat@libevent.org>
Mon, 18 May 2020 22:06:12 +0000 (01:06 +0300)
Refs: #182

http.c

diff --git a/http.c b/http.c
index 09feb1965ae50f2b6c1bb62d1d00abc3f24ca4bb..15aac6619bc88125b9ca613fac2ff1d157d121d9 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1492,8 +1492,10 @@ static void
 evhttp_connection_cb_cleanup(struct evhttp_connection *evcon)
 {
        struct evcon_requestq requests;
+       EVUTIL_ASSERT(evcon->flags & EVHTTP_CON_OUTGOING);
 
        evhttp_connection_reset_(evcon);
+
        if (evcon->retry_max < 0 || evcon->retry_cnt < evcon->retry_max) {
                struct timeval tv_retry = evcon->initial_retry_timeout;
                int i;
@@ -1539,6 +1541,12 @@ evhttp_connection_cb_cleanup(struct evhttp_connection *evcon)
                request->cb(request, request->cb_arg);
                evhttp_request_free_auto(request);
        }
+
+       if (TAILQ_FIRST(&evcon->requests) == NULL
+         && (evcon->flags & EVHTTP_CON_AUTOFREE)) {
+               evhttp_connection_free(evcon);
+       }
+
 }
 
 static void