diff --git a/src/unix/threadpool.c b/src/unix/threadpool.c index a11cf6ec..d5d81392 100644 --- a/src/unix/threadpool.c +++ b/src/unix/threadpool.c @@ -153,8 +153,7 @@ void uv__work_done(uv_async_t* handle, int status) { static void uv__queue_work(struct uv__work* w) { uv_work_t* req = container_of(w, uv_work_t, work_req); - if (req->work_cb) - req->work_cb(req); + req->work_cb(req); } @@ -172,6 +171,9 @@ int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb) { + if (work_cb == NULL) + return uv__set_artificial_error(loop, UV_EINVAL); + uv__req_init(loop, req, UV_WORK); req->loop = loop; req->work_cb = work_cb; diff --git a/src/win/threadpool.c b/src/win/threadpool.c index c1a71c18..5118fd94 100644 --- a/src/win/threadpool.c +++ b/src/win/threadpool.c @@ -55,6 +55,9 @@ static DWORD WINAPI uv_work_thread_proc(void* parameter) { int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb) { + if (work_cb == NULL) + return uv__set_artificial_error(loop, UV_EINVAL); + uv_work_req_init(loop, req, work_cb, after_work_cb); if (!QueueUserWorkItem(&uv_work_thread_proc, req, WT_EXECUTELONGFUNCTION)) { diff --git a/test/test-list.h b/test/test-list.h index ffa68360..f5cc95c6 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -184,6 +184,7 @@ TEST_DECLARE (fs_readdir_file) TEST_DECLARE (fs_open_dir) TEST_DECLARE (fs_rename_to_existing_file) TEST_DECLARE (threadpool_queue_work_simple) +TEST_DECLARE (threadpool_queue_work_einval) TEST_DECLARE (threadpool_multiple_event_loops) TEST_DECLARE (thread_mutex) TEST_DECLARE (thread_rwlock) @@ -448,6 +449,7 @@ TASK_LIST_START TEST_ENTRY (fs_open_dir) TEST_ENTRY (fs_rename_to_existing_file) TEST_ENTRY (threadpool_queue_work_simple) + TEST_ENTRY (threadpool_queue_work_einval) TEST_ENTRY (threadpool_multiple_event_loops) TEST_ENTRY (thread_mutex) TEST_ENTRY (thread_rwlock) diff --git a/test/test-threadpool.c b/test/test-threadpool.c index 12777b6e..2b226196 100644 --- a/test/test-threadpool.c +++ b/test/test-threadpool.c @@ -56,3 +56,21 @@ TEST_IMPL(threadpool_queue_work_simple) { MAKE_VALGRIND_HAPPY(); return 0; } + + +TEST_IMPL(threadpool_queue_work_einval) { + int r; + + work_req.data = &data; + r = uv_queue_work(uv_default_loop(), &work_req, NULL, after_work_cb); + ASSERT(r == -1); + + uv_run(uv_default_loop()); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); + + ASSERT(work_cb_count == 0); + ASSERT(after_work_cb_count == 0); + + MAKE_VALGRIND_HAPPY(); + return 0; +}