test-fdleak: fix memory leaks

Fixes: #726
This commit is contained in:
Azat Khuzhin 2018-12-08 17:35:53 +03:00
parent 3e6bec7c1a
commit e5ec52d100
No known key found for this signature in database
GPG Key ID: B86086848EF8686D

View File

@ -95,8 +95,11 @@ server_event_cb(struct bufferevent *bev, short events, void *ctx)
if (events & BEV_EVENT_ERROR) {
my_perror("Error from bufferevent");
exit(1);
} else if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
} else if (events & BEV_EVENT_EOF) {
bufferevent_free(bev);
if (num_requests == MAX_REQUESTS) {
event_base_loopbreak(bufferevent_get_base(bev));
}
}
}
@ -107,8 +110,7 @@ listener_accept_cb(struct evconnlistener *listener, evutil_socket_t sock,
{
struct event_base *base = evconnlistener_get_base(listener);
struct bufferevent *bev = bufferevent_socket_new(base, sock,
BEV_OPT_CLOSE_ON_FREE);
BEV_OPT_CLOSE_ON_FREE);
bufferevent_setcb(bev, server_read_cb, NULL, server_event_cb, NULL);
bufferevent_enable(bev, EV_READ|EV_WRITE);
}
@ -154,6 +156,9 @@ start_loop(void)
start_client(base);
event_base_dispatch(base);
evconnlistener_free(listener);
event_base_free(base);
}
/*
@ -178,9 +183,7 @@ client_read_cb(struct bufferevent *bev, void *ctx)
bufferevent_free(bev);
num_requests++;
if (num_requests == MAX_REQUESTS) {
event_base_loopbreak(base);
} else {
if (++num_requests < MAX_REQUESTS) {
start_client(base);
}
}