From 2ee2d4622a6f00133f2a46f5cf5956ea1485c5ba Mon Sep 17 00:00:00 2001 From: seny Date: Tue, 13 Aug 2019 15:07:24 -0700 Subject: [PATCH] timer: fix uv_timer_start on closing timer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return `UV_EINVAL` in this case. Fixes: https://github.com/libuv/libuv/issues/2416 PR-URL: https://github.com/libuv/libuv/pull/2424 Reviewed-By: Anna Henningsen Reviewed-By: Santiago Gimeno Reviewed-By: Saúl Ibarra Corretgé Reviewed-By: Colin Ihrig --- src/timer.c | 2 +- test/test-list.h | 2 ++ test/test-timer.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/timer.c b/src/timer.c index dd78bcba..8fce7f64 100644 --- a/src/timer.c +++ b/src/timer.c @@ -74,7 +74,7 @@ int uv_timer_start(uv_timer_t* handle, uint64_t repeat) { uint64_t clamped_timeout; - if (cb == NULL) + if (uv__is_closing(handle) || cb == NULL) return UV_EINVAL; if (uv__is_active(handle)) diff --git a/test/test-list.h b/test/test-list.h index 930bb6af..b6066f27 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -197,6 +197,7 @@ TEST_DECLARE (timer_huge_timeout) TEST_DECLARE (timer_huge_repeat) TEST_DECLARE (timer_run_once) TEST_DECLARE (timer_from_check) +TEST_DECLARE (timer_is_closing) TEST_DECLARE (timer_null_callback) TEST_DECLARE (timer_early_check) TEST_DECLARE (idle_starvation) @@ -729,6 +730,7 @@ TASK_LIST_START TEST_ENTRY (timer_huge_repeat) TEST_ENTRY (timer_run_once) TEST_ENTRY (timer_from_check) + TEST_ENTRY (timer_is_closing) TEST_ENTRY (timer_null_callback) TEST_ENTRY (timer_early_check) diff --git a/test/test-timer.c b/test/test-timer.c index 080a7300..c667da00 100644 --- a/test/test-timer.c +++ b/test/test-timer.c @@ -292,6 +292,19 @@ TEST_IMPL(timer_run_once) { } +TEST_IMPL(timer_is_closing) { + uv_timer_t handle; + + ASSERT(0 == uv_timer_init(uv_default_loop(), &handle)); + uv_close((uv_handle_t *)&handle, NULL); + + ASSERT(UV_EINVAL == uv_timer_start(&handle, never_cb, 100, 100)); + + MAKE_VALGRIND_HAPPY(); + return 0; +} + + TEST_IMPL(timer_null_callback) { uv_timer_t handle;