mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-18 16:54:42 -04:00
test: fix memory leaks for https (add BEV_OPT_CLOSE_ON_FREE)
- http/https_filter_basic - http/https_filter_chunk_out (cherry picked from commit ec94a6bb3f9d950101d07b2a2e092b675d5aa3f0)
This commit is contained in:
parent
3c2c856de4
commit
ccd6724300
@ -461,9 +461,9 @@ http_chunked_cb(struct evhttp_request *req, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct bufferevent *
|
static struct bufferevent *
|
||||||
create_bev(struct event_base *base, evutil_socket_t fd, int ssl_mask)
|
create_bev(struct event_base *base, evutil_socket_t fd, int ssl_mask, int flags_)
|
||||||
{
|
{
|
||||||
int flags = BEV_OPT_DEFER_CALLBACKS;
|
int flags = BEV_OPT_DEFER_CALLBACKS | flags_;
|
||||||
struct bufferevent *bev = NULL;
|
struct bufferevent *bev = NULL;
|
||||||
|
|
||||||
if (!ssl_mask) {
|
if (!ssl_mask) {
|
||||||
@ -526,7 +526,7 @@ http_basic_test_impl(void *arg, int ssl, const char *request_line)
|
|||||||
fd = http_connect("127.0.0.1", port);
|
fd = http_connect("127.0.0.1", port);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
bev = create_bev(data->base, fd, ssl);
|
bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
|
||||||
bufferevent_setcb(bev, http_readcb, http_half_writecb,
|
bufferevent_setcb(bev, http_readcb, http_half_writecb,
|
||||||
http_errorcb, data->base);
|
http_errorcb, data->base);
|
||||||
out = bufferevent_get_output(bev);
|
out = bufferevent_get_output(bev);
|
||||||
@ -542,12 +542,11 @@ http_basic_test_impl(void *arg, int ssl, const char *request_line)
|
|||||||
|
|
||||||
/* connect to the second port */
|
/* connect to the second port */
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
evutil_closesocket(fd);
|
|
||||||
|
|
||||||
fd = http_connect("127.0.0.1", port2);
|
fd = http_connect("127.0.0.1", port2);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
bev = create_bev(data->base, fd, ssl);
|
bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
|
||||||
bufferevent_setcb(bev, http_readcb, http_writecb,
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
||||||
http_errorcb, data->base);
|
http_errorcb, data->base);
|
||||||
out = bufferevent_get_output(bev);
|
out = bufferevent_get_output(bev);
|
||||||
@ -564,12 +563,11 @@ http_basic_test_impl(void *arg, int ssl, const char *request_line)
|
|||||||
|
|
||||||
/* Connect to the second port again. This time, send an absolute uri. */
|
/* Connect to the second port again. This time, send an absolute uri. */
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
evutil_closesocket(fd);
|
|
||||||
|
|
||||||
fd = http_connect("127.0.0.1", port2);
|
fd = http_connect("127.0.0.1", port2);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
bev = create_bev(data->base, fd, ssl);
|
bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
|
||||||
bufferevent_setcb(bev, http_readcb, http_writecb,
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
||||||
http_errorcb, data->base);
|
http_errorcb, data->base);
|
||||||
|
|
||||||
@ -3120,7 +3118,7 @@ http_incomplete_test_(struct basic_test_data *data, int use_timeout, int ssl)
|
|||||||
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
bev = create_bev(data->base, fd, ssl);
|
bev = create_bev(data->base, fd, ssl, 0);
|
||||||
bufferevent_setcb(bev,
|
bufferevent_setcb(bev,
|
||||||
http_incomplete_readcb, http_incomplete_writecb,
|
http_incomplete_readcb, http_incomplete_writecb,
|
||||||
http_incomplete_errorcb, use_timeout ? NULL : &fd);
|
http_incomplete_errorcb, use_timeout ? NULL : &fd);
|
||||||
@ -3320,7 +3318,7 @@ static void
|
|||||||
http_chunk_out_test_impl(void *arg, int ssl)
|
http_chunk_out_test_impl(void *arg, int ssl)
|
||||||
{
|
{
|
||||||
struct basic_test_data *data = arg;
|
struct basic_test_data *data = arg;
|
||||||
struct bufferevent *bev;
|
struct bufferevent *bev = NULL;
|
||||||
evutil_socket_t fd;
|
evutil_socket_t fd;
|
||||||
const char *http_request;
|
const char *http_request;
|
||||||
ev_uint16_t port = 0;
|
ev_uint16_t port = 0;
|
||||||
@ -3337,7 +3335,7 @@ http_chunk_out_test_impl(void *arg, int ssl)
|
|||||||
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
bev = create_bev(data->base, fd, ssl);
|
bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
|
||||||
bufferevent_setcb(bev,
|
bufferevent_setcb(bev,
|
||||||
http_chunked_readcb, http_chunked_writecb,
|
http_chunked_readcb, http_chunked_writecb,
|
||||||
http_chunked_errorcb, data->base);
|
http_chunked_errorcb, data->base);
|
||||||
@ -3355,6 +3353,7 @@ http_chunk_out_test_impl(void *arg, int ssl)
|
|||||||
event_base_dispatch(data->base);
|
event_base_dispatch(data->base);
|
||||||
|
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
|
bev = NULL;
|
||||||
|
|
||||||
evutil_gettimeofday(&tv_end, NULL);
|
evutil_gettimeofday(&tv_end, NULL);
|
||||||
evutil_timersub(&tv_end, &tv_start, &tv_end);
|
evutil_timersub(&tv_end, &tv_start, &tv_end);
|
||||||
@ -3364,7 +3363,7 @@ http_chunk_out_test_impl(void *arg, int ssl)
|
|||||||
tt_int_op(test_ok, ==, 2);
|
tt_int_op(test_ok, ==, 2);
|
||||||
|
|
||||||
/* now try again with the regular connection object */
|
/* now try again with the regular connection object */
|
||||||
bev = create_bev(data->base, -1, ssl);
|
bev = create_bev(data->base, -1, ssl, BEV_OPT_CLOSE_ON_FREE);
|
||||||
evcon = evhttp_connection_base_bufferevent_new(
|
evcon = evhttp_connection_base_bufferevent_new(
|
||||||
data->base, NULL, bev, "127.0.0.1", port);
|
data->base, NULL, bev, "127.0.0.1", port);
|
||||||
tt_assert(evcon);
|
tt_assert(evcon);
|
||||||
@ -3372,14 +3371,13 @@ http_chunk_out_test_impl(void *arg, int ssl)
|
|||||||
/* make two requests to check the keepalive behavior */
|
/* make two requests to check the keepalive behavior */
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
req = evhttp_request_new(http_chunked_request_done,data->base);
|
req = evhttp_request_new(http_chunked_request_done, data->base);
|
||||||
|
|
||||||
/* Add the information that we care about */
|
/* Add the information that we care about */
|
||||||
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
||||||
|
|
||||||
/* We give ownership of the request to the connection */
|
/* We give ownership of the request to the connection */
|
||||||
if (evhttp_make_request(evcon, req,
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/chunked") == -1) {
|
||||||
EVHTTP_REQ_GET, "/chunked") == -1) {
|
|
||||||
tt_abort_msg("Couldn't make request");
|
tt_abort_msg("Couldn't make request");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3410,7 +3408,7 @@ http_stream_out_test_impl(void *arg, int ssl)
|
|||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
exit_base = data->base;
|
exit_base = data->base;
|
||||||
|
|
||||||
bev = create_bev(data->base, -1, ssl);
|
bev = create_bev(data->base, -1, ssl, 0);
|
||||||
evcon = evhttp_connection_base_bufferevent_new(
|
evcon = evhttp_connection_base_bufferevent_new(
|
||||||
data->base, NULL, bev, "127.0.0.1", port);
|
data->base, NULL, bev, "127.0.0.1", port);
|
||||||
tt_assert(evcon);
|
tt_assert(evcon);
|
||||||
@ -3610,7 +3608,7 @@ http_connection_fail_test_impl(void *arg, int ssl)
|
|||||||
/* auto detect a port */
|
/* auto detect a port */
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
bev = create_bev(data->base, -1, ssl);
|
bev = create_bev(data->base, -1, ssl, 0);
|
||||||
/* Pick an unroutable address. This administratively scoped multicast
|
/* Pick an unroutable address. This administratively scoped multicast
|
||||||
* address should do when working with TCP. */
|
* address should do when working with TCP. */
|
||||||
evcon = evhttp_connection_base_bufferevent_new(
|
evcon = evhttp_connection_base_bufferevent_new(
|
||||||
@ -3682,7 +3680,7 @@ http_simple_test_impl(void *arg, int ssl, int dirty, const char *uri)
|
|||||||
exit_base = data->base;
|
exit_base = data->base;
|
||||||
test_ok = 0;
|
test_ok = 0;
|
||||||
|
|
||||||
bev = create_bev(data->base, -1, ssl);
|
bev = create_bev(data->base, -1, ssl, 0);
|
||||||
#ifdef EVENT__HAVE_OPENSSL
|
#ifdef EVENT__HAVE_OPENSSL
|
||||||
bufferevent_openssl_set_allow_dirty_shutdown(bev, dirty);
|
bufferevent_openssl_set_allow_dirty_shutdown(bev, dirty);
|
||||||
#endif
|
#endif
|
||||||
@ -3729,7 +3727,7 @@ http_connection_retry_test_basic(void *arg, const char *addr, struct evdns_base
|
|||||||
/* auto detect a port */
|
/* auto detect a port */
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
|
|
||||||
bev = create_bev(data->base, -1, ssl);
|
bev = create_bev(data->base, -1, ssl, 0);
|
||||||
evcon = evhttp_connection_base_bufferevent_new(data->base, dns_base, bev, addr, hs.port);
|
evcon = evhttp_connection_base_bufferevent_new(data->base, dns_base, bev, addr, hs.port);
|
||||||
tt_assert(evcon);
|
tt_assert(evcon);
|
||||||
if (dns_base)
|
if (dns_base)
|
||||||
@ -4517,7 +4515,7 @@ http_write_during_read_test_impl(void *arg, int ssl)
|
|||||||
|
|
||||||
fd = http_connect("127.0.0.1", port);
|
fd = http_connect("127.0.0.1", port);
|
||||||
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
||||||
bev = create_bev(data->base, fd, 0);
|
bev = create_bev(data->base, fd, 0, 0);
|
||||||
bufferevent_setcb(bev, NULL, NULL, NULL, data->base);
|
bufferevent_setcb(bev, NULL, NULL, NULL, data->base);
|
||||||
bufferevent_disable(bev, EV_READ);
|
bufferevent_disable(bev, EV_READ);
|
||||||
|
|
||||||
@ -4589,7 +4587,7 @@ static void http_run_bev_request(struct event_base *base, int port,
|
|||||||
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
||||||
|
|
||||||
/* Stupid thing to send a request */
|
/* Stupid thing to send a request */
|
||||||
bev = create_bev(base, fd, 0);
|
bev = create_bev(base, fd, 0, 0);
|
||||||
bufferevent_setcb(bev, http_readcb, http_writecb,
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
||||||
http_errorcb, base);
|
http_errorcb, base);
|
||||||
out = bufferevent_get_output(bev);
|
out = bufferevent_get_output(bev);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user