test: avoid malloc() in threadpool test

Stack-allocate the `uv_loop_t` instance, no reason to heap-allocate it.

PR-URL: https://github.com/libuv/libuv/pull/1634
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Ben Noordhuis 2017-11-19 13:23:08 +01:00
parent e99ac4c1f4
commit 9594719e73

View File

@ -107,34 +107,28 @@ static void fs_cb(uv_fs_t* handle) {
static void do_work(void* arg) {
struct getaddrinfo_req getaddrinfo_reqs[16];
struct fs_req fs_reqs[16];
uv_loop_t* loop;
uv_loop_t loop;
size_t i;
int r;
struct test_thread* thread = arg;
loop = malloc(sizeof *loop);
ASSERT(loop != NULL);
ASSERT(0 == uv_loop_init(loop));
ASSERT(0 == uv_loop_init(&loop));
for (i = 0; i < ARRAY_SIZE(getaddrinfo_reqs); i++) {
struct getaddrinfo_req* req = getaddrinfo_reqs + i;
req->counter = 16;
req->loop = loop;
req->loop = &loop;
getaddrinfo_do(req);
}
for (i = 0; i < ARRAY_SIZE(fs_reqs); i++) {
struct fs_req* req = fs_reqs + i;
req->counter = 16;
req->loop = loop;
req->loop = &loop;
fs_do(req);
}
r = uv_run(loop, UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT(0 == uv_loop_close(loop));
free(loop);
ASSERT(0 == uv_run(&loop, UV_RUN_DEFAULT));
ASSERT(0 == uv_loop_close(&loop));
thread->thread_called = 1;
}