From 9594719e737f3f99aafeb48645d67da0684341c2 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 19 Nov 2017 13:23:08 +0100 Subject: [PATCH] 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 --- test/test-thread.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/test-thread.c b/test/test-thread.c index b0e87e20..dac6d685 100644 --- a/test/test-thread.c +++ b/test/test-thread.c @@ -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; }