mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Fix several memory leaks in the unit tests.
Also add a comment to buffer.c about why we call evbuffer_file_segment_free on failure to add the segment.
This commit is contained in:
parent
364c110687
commit
89c1a3b7fe
2
buffer.c
2
buffer.c
@ -3203,7 +3203,7 @@ evbuffer_add_file_segment(struct evbuffer *buf,
|
|||||||
return 0;
|
return 0;
|
||||||
err:
|
err:
|
||||||
EVBUFFER_UNLOCK(buf);
|
EVBUFFER_UNLOCK(buf);
|
||||||
evbuffer_file_segment_free(seg);
|
evbuffer_file_segment_free(seg); /* Lowers the refcount */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1673,7 +1673,7 @@ static void
|
|||||||
test_active_later(void *ptr)
|
test_active_later(void *ptr)
|
||||||
{
|
{
|
||||||
struct basic_test_data *data = ptr;
|
struct basic_test_data *data = ptr;
|
||||||
struct event *ev1, *ev2;
|
struct event *ev1 = NULL, *ev2 = NULL;
|
||||||
struct event ev3, ev4;
|
struct event ev3, ev4;
|
||||||
struct timeval qsec = {0, 100000};
|
struct timeval qsec = {0, 100000};
|
||||||
ev1 = event_new(data->base, data->pair[0], EV_READ|EV_PERSIST, read_and_drain_cb, NULL);
|
ev1 = event_new(data->base, data->pair[0], EV_READ|EV_PERSIST, read_and_drain_cb, NULL);
|
||||||
@ -1708,10 +1708,15 @@ test_active_later(void *ptr)
|
|||||||
* it. */
|
* it. */
|
||||||
event_active_later_(&ev3, EV_READ);
|
event_active_later_(&ev3, EV_READ);
|
||||||
event_base_assert_ok_(data->base);
|
event_base_assert_ok_(data->base);
|
||||||
|
|
||||||
|
end:
|
||||||
|
if (ev1)
|
||||||
|
event_free(ev1);
|
||||||
|
if (ev2)
|
||||||
|
event_free(ev2);
|
||||||
|
|
||||||
event_base_free(data->base);
|
event_base_free(data->base);
|
||||||
data->base = NULL;
|
data->base = NULL;
|
||||||
end:
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -819,7 +819,6 @@ test_evbuffer_add_file(void *ptr)
|
|||||||
if (use_segment) {
|
if (use_segment) {
|
||||||
tt_assert(evbuffer_add_file_segment(src, seg,
|
tt_assert(evbuffer_add_file_segment(src, seg,
|
||||||
segment_offset, segment_len)!=-1);
|
segment_offset, segment_len)!=-1);
|
||||||
seg = NULL; /* Avoid double-free */
|
|
||||||
} else {
|
} else {
|
||||||
tt_assert(evbuffer_add_file(src, fd, starting_offset,
|
tt_assert(evbuffer_add_file(src, fd, starting_offset,
|
||||||
mapping_len) != -1);
|
mapping_len) != -1);
|
||||||
@ -864,6 +863,10 @@ test_evbuffer_add_file(void *ptr)
|
|||||||
evutil_closesocket(pair[0]);
|
evutil_closesocket(pair[0]);
|
||||||
if (pair[1] >= 0)
|
if (pair[1] >= 0)
|
||||||
evutil_closesocket(pair[1]);
|
evutil_closesocket(pair[1]);
|
||||||
|
if (wev)
|
||||||
|
event_free(wev);
|
||||||
|
if (rev)
|
||||||
|
event_free(rev);
|
||||||
if (tmpfilename) {
|
if (tmpfilename) {
|
||||||
unlink(tmpfilename);
|
unlink(tmpfilename);
|
||||||
free(tmpfilename);
|
free(tmpfilename);
|
||||||
|
@ -870,8 +870,12 @@ dns_inflight_test_impl(void *arg, int flags)
|
|||||||
end:
|
end:
|
||||||
if (dns)
|
if (dns)
|
||||||
evdns_base_free(dns, 0);
|
evdns_base_free(dns, 0);
|
||||||
if (exit_port)
|
if (exit_port) {
|
||||||
evdns_close_server_port(exit_port);
|
evdns_close_server_port(exit_port);
|
||||||
|
exit_port = NULL;
|
||||||
|
} else if (! disable_when_inactive) {
|
||||||
|
evdns_close_server_port(dns_port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1861,6 +1865,7 @@ dbg_leak_resume(void *env_, int cancel, int send_err_shutdown)
|
|||||||
end:
|
end:
|
||||||
evdns_base_free(env->dns_base, send_err_shutdown);
|
evdns_base_free(env->dns_base, send_err_shutdown);
|
||||||
env->dns_base = 0;
|
env->dns_base = 0;
|
||||||
|
|
||||||
event_base_free(env->base);
|
event_base_free(env->base);
|
||||||
env->base = 0;
|
env->base = 0;
|
||||||
}
|
}
|
||||||
|
@ -399,7 +399,7 @@ http_basic_test(void *arg)
|
|||||||
{
|
{
|
||||||
struct basic_test_data *data = arg;
|
struct basic_test_data *data = arg;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
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, port2 = 0;
|
ev_uint16_t port = 0, port2 = 0;
|
||||||
@ -484,7 +484,8 @@ http_basic_test(void *arg)
|
|||||||
|
|
||||||
evhttp_free(http);
|
evhttp_free(http);
|
||||||
end:
|
end:
|
||||||
;
|
if (bev)
|
||||||
|
bufferevent_free(bev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -194,6 +194,7 @@ respond_to_number(struct bufferevent *bev, void *ctx)
|
|||||||
n = atoi(line);
|
n = atoi(line);
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
TT_FAIL(("Bad number: %s", line));
|
TT_FAIL(("Bad number: %s", line));
|
||||||
|
free(line);
|
||||||
TT_BLATHER(("The number was %d", n));
|
TT_BLATHER(("The number was %d", n));
|
||||||
if (n == 1001) {
|
if (n == 1001) {
|
||||||
++test_is_done;
|
++test_is_done;
|
||||||
|
@ -382,7 +382,8 @@ thread_conditions_simple(void *arg)
|
|||||||
tt_int_op(n_signal, ==, 1);
|
tt_int_op(n_signal, ==, 1);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
;
|
EVTHREAD_FREE_LOCK(cond.lock, EVTHREAD_LOCKTYPE_RECURSIVE);
|
||||||
|
EVTHREAD_FREE_COND(cond.cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CB_COUNT 128
|
#define CB_COUNT 128
|
||||||
|
Loading…
x
Reference in New Issue
Block a user