diff --git a/src/unix/loop-watcher.c b/src/unix/loop-watcher.c index 9d1414b8..a07569e4 100644 --- a/src/unix/loop-watcher.c +++ b/src/unix/loop-watcher.c @@ -31,6 +31,8 @@ \ int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \ if (uv__is_active(handle)) return 0; \ + if (cb == NULL) \ + return uv__set_artificial_error(handle->loop, UV_EINVAL); \ ngx_queue_insert_head(&handle->loop->name##_handles, &handle->queue); \ handle->name##_cb = cb; \ uv__handle_start(handle); \ @@ -49,7 +51,7 @@ ngx_queue_t* q; \ ngx_queue_foreach(q, &loop->name##_handles) { \ h = ngx_queue_data(q, uv_##name##_t, queue); \ - if (h->name##_cb) h->name##_cb(h, 0); \ + h->name##_cb(h, 0); \ } \ } \ \ diff --git a/src/win/loop-watcher.c b/src/win/loop-watcher.c index 9fff631c..65080ff6 100644 --- a/src/win/loop-watcher.c +++ b/src/win/loop-watcher.c @@ -52,6 +52,9 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) { if (handle->flags & UV_HANDLE_ACTIVE) \ return 0; \ \ + if (cb == NULL) \ + return uv__set_artificial_error(handle->loop, UV_EINVAL); \ + \ old_head = loop->name##_handles; \ \ handle->name##_next = old_head; \ diff --git a/test/test-ref.c b/test/test-ref.c index bc0030d3..027af16f 100644 --- a/test/test-ref.c +++ b/test/test-ref.c @@ -58,6 +58,11 @@ static void fail_cb(void) { } +static void fail_cb2() { + ASSERT(0 && "fail_cb2 should not have been called"); +} + + static void req_cb(uv_handle_t* req, int status) { req_cb_called++; } @@ -104,7 +109,7 @@ TEST_IMPL(ref) { TEST_IMPL(idle_ref) { uv_idle_t h; uv_idle_init(uv_default_loop(), &h); - uv_idle_start(&h, NULL); + uv_idle_start(&h, fail_cb2); uv_unref((uv_handle_t*)&h); uv_run(uv_default_loop()); do_close(&h); @@ -127,7 +132,7 @@ TEST_IMPL(async_ref) { TEST_IMPL(prepare_ref) { uv_prepare_t h; uv_prepare_init(uv_default_loop(), &h); - uv_prepare_start(&h, NULL); + uv_prepare_start(&h, fail_cb2); uv_unref((uv_handle_t*)&h); uv_run(uv_default_loop()); do_close(&h); @@ -139,7 +144,7 @@ TEST_IMPL(prepare_ref) { TEST_IMPL(check_ref) { uv_check_t h; uv_check_init(uv_default_loop(), &h); - uv_check_start(&h, NULL); + uv_check_start(&h, fail_cb2); uv_unref((uv_handle_t*)&h); uv_run(uv_default_loop()); do_close(&h);