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;
|
||||
err:
|
||||
EVBUFFER_UNLOCK(buf);
|
||||
evbuffer_file_segment_free(seg);
|
||||
evbuffer_file_segment_free(seg); /* Lowers the refcount */
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1673,7 +1673,7 @@ static void
|
||||
test_active_later(void *ptr)
|
||||
{
|
||||
struct basic_test_data *data = ptr;
|
||||
struct event *ev1, *ev2;
|
||||
struct event *ev1 = NULL, *ev2 = NULL;
|
||||
struct event ev3, ev4;
|
||||
struct timeval qsec = {0, 100000};
|
||||
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. */
|
||||
event_active_later_(&ev3, EV_READ);
|
||||
event_base_assert_ok_(data->base);
|
||||
|
||||
end:
|
||||
if (ev1)
|
||||
event_free(ev1);
|
||||
if (ev2)
|
||||
event_free(ev2);
|
||||
|
||||
event_base_free(data->base);
|
||||
data->base = NULL;
|
||||
end:
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
@ -819,7 +819,6 @@ test_evbuffer_add_file(void *ptr)
|
||||
if (use_segment) {
|
||||
tt_assert(evbuffer_add_file_segment(src, seg,
|
||||
segment_offset, segment_len)!=-1);
|
||||
seg = NULL; /* Avoid double-free */
|
||||
} else {
|
||||
tt_assert(evbuffer_add_file(src, fd, starting_offset,
|
||||
mapping_len) != -1);
|
||||
@ -864,6 +863,10 @@ test_evbuffer_add_file(void *ptr)
|
||||
evutil_closesocket(pair[0]);
|
||||
if (pair[1] >= 0)
|
||||
evutil_closesocket(pair[1]);
|
||||
if (wev)
|
||||
event_free(wev);
|
||||
if (rev)
|
||||
event_free(rev);
|
||||
if (tmpfilename) {
|
||||
unlink(tmpfilename);
|
||||
free(tmpfilename);
|
||||
|
@ -870,8 +870,12 @@ dns_inflight_test_impl(void *arg, int flags)
|
||||
end:
|
||||
if (dns)
|
||||
evdns_base_free(dns, 0);
|
||||
if (exit_port)
|
||||
if (exit_port) {
|
||||
evdns_close_server_port(exit_port);
|
||||
exit_port = NULL;
|
||||
} else if (! disable_when_inactive) {
|
||||
evdns_close_server_port(dns_port);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1861,6 +1865,7 @@ dbg_leak_resume(void *env_, int cancel, int send_err_shutdown)
|
||||
end:
|
||||
evdns_base_free(env->dns_base, send_err_shutdown);
|
||||
env->dns_base = 0;
|
||||
|
||||
event_base_free(env->base);
|
||||
env->base = 0;
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ http_basic_test(void *arg)
|
||||
{
|
||||
struct basic_test_data *data = arg;
|
||||
struct timeval tv;
|
||||
struct bufferevent *bev;
|
||||
struct bufferevent *bev = NULL;
|
||||
evutil_socket_t fd;
|
||||
const char *http_request;
|
||||
ev_uint16_t port = 0, port2 = 0;
|
||||
@ -484,7 +484,8 @@ http_basic_test(void *arg)
|
||||
|
||||
evhttp_free(http);
|
||||
end:
|
||||
;
|
||||
if (bev)
|
||||
bufferevent_free(bev);
|
||||
}
|
||||
|
||||
|
||||
|
@ -194,6 +194,7 @@ respond_to_number(struct bufferevent *bev, void *ctx)
|
||||
n = atoi(line);
|
||||
if (n <= 0)
|
||||
TT_FAIL(("Bad number: %s", line));
|
||||
free(line);
|
||||
TT_BLATHER(("The number was %d", n));
|
||||
if (n == 1001) {
|
||||
++test_is_done;
|
||||
|
@ -382,7 +382,8 @@ thread_conditions_simple(void *arg)
|
||||
tt_int_op(n_signal, ==, 1);
|
||||
|
||||
end:
|
||||
;
|
||||
EVTHREAD_FREE_LOCK(cond.lock, EVTHREAD_LOCKTYPE_RECURSIVE);
|
||||
EVTHREAD_FREE_COND(cond.cond);
|
||||
}
|
||||
|
||||
#define CB_COUNT 128
|
||||
|
Loading…
x
Reference in New Issue
Block a user