]> granicus.if.org Git - libevent/commitdiff
http: set fd to -1 unconditioally, to avoid leaking of DNS requests
authorAzat Khuzhin <a3at.mail@gmail.com>
Thu, 24 Mar 2016 10:38:05 +0000 (13:38 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Thu, 24 Mar 2016 11:01:31 +0000 (14:01 +0300)
Otherwise:
http/cancel_by_host_ns_timeout_inactive_server: [msg] Nameserver 127.0.0.1:37035 has failed: request timed out.
[msg] All nameservers have failed
OK
1 tests ok.  (0 skipped)
==26211==
==26211== FILE DESCRIPTORS: 3 open at exit.
==26211== Open file descriptor 2: /dev/pts/47
==26211==    <inherited from parent>
==26211==
==26211== Open file descriptor 1: /dev/pts/47
==26211==    <inherited from parent>
==26211==
==26211== Open file descriptor 0: /dev/pts/47
==26211==    <inherited from parent>
==26211==
==26211==
==26211== HEAP SUMMARY:
==26211==     in use at exit: 1,112 bytes in 5 blocks
==26211==   total heap usage: 149 allocs, 144 frees, 18,826 bytes allocated
==26211==
==26211== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x498F5B: evbuffer_add_cb (buffer.c:3309)
==26211==    by 0x4A0EF5: bufferevent_socket_new (bufferevent_sock.c:366)
==26211==    by 0x4BFADF: evhttp_connection_base_bufferevent_new (http.c:2375)
==26211==    by 0x4BFC8F: evhttp_connection_base_new (http.c:2427)
==26211==    by 0x460DAA: http_cancel_test (regress_http.c:1417)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x491FF0: evbuffer_new (buffer.c:365)
==26211==    by 0x49A1BE: bufferevent_init_common_ (bufferevent.c:300)
==26211==    by 0x4A0E44: bufferevent_socket_new (bufferevent_sock.c:353)
==26211==    by 0x4BFADF: evhttp_connection_base_bufferevent_new (http.c:2375)
==26211==    by 0x4BFC8F: evhttp_connection_base_new (http.c:2427)
==26211==    by 0x460DAA: http_cancel_test (regress_http.c:1417)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x491FF0: evbuffer_new (buffer.c:365)
==26211==    by 0x49A1FB: bufferevent_init_common_ (bufferevent.c:305)
==26211==    by 0x4A0E44: bufferevent_socket_new (bufferevent_sock.c:353)
==26211==    by 0x4BFADF: evhttp_connection_base_bufferevent_new (http.c:2375)
==26211==    by 0x4BFC8F: evhttp_connection_base_new (http.c:2427)
==26211==    by 0x460DAA: http_cancel_test (regress_http.c:1417)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== 536 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x4A0E15: bufferevent_socket_new (bufferevent_sock.c:350)
==26211==    by 0x4BFADF: evhttp_connection_base_bufferevent_new (http.c:2375)
==26211==    by 0x4BFC8F: evhttp_connection_base_new (http.c:2427)
==26211==    by 0x460DAA: http_cancel_test (regress_http.c:1417)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== 1,112 (264 direct, 848 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x4D0564: evdns_getaddrinfo (evdns.c:4685)
==26211==    by 0x4B13BA: evutil_getaddrinfo_async_ (evutil.c:1575)
==26211==    by 0x4A139E: bufferevent_socket_connect_hostname (bufferevent_sock.c:524)
==26211==    by 0x4C02DB: evhttp_connection_connect_ (http.c:2588)
==26211==    by 0x4C04DD: evhttp_make_request (http.c:2643)
==26211==    by 0x4615FF: http_cancel_test (regress_http.c:1504)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== LEAK SUMMARY:
==26211==    definitely lost: 264 bytes in 1 blocks
==26211==    indirectly lost: 848 bytes in 4 blocks
==26211==      possibly lost: 0 bytes in 0 blocks
==26211==    still reachable: 0 bytes in 0 blocks
==26211==         suppressed: 0 bytes in 0 blocks

http.c

diff --git a/http.c b/http.c
index a12d77316dc3dff6457a85dc2fa229454def0a39..ac146075e1e11ef9a0b86196ea16f8419b8e595f 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1342,9 +1342,9 @@ evhttp_connection_reset_(struct evhttp_connection *evcon)
 
                shutdown(evcon->fd, EVUTIL_SHUT_WR);
                evutil_closesocket(evcon->fd);
-               bufferevent_setfd(evcon->bufev, -1);
                evcon->fd = -1;
        }
+       bufferevent_setfd(evcon->bufev, -1);
 
        /* we need to clean up any buffered data */
        tmp = bufferevent_get_output(evcon->bufev);