diff --git a/src/wrapper/timer.cc b/src/wrapper/timer.cc index 4ee4cfb3887..9226b1d5fda 100644 --- a/src/wrapper/timer.cc +++ b/src/wrapper/timer.cc @@ -42,10 +42,18 @@ TimerNode *swoole_timer_add(long ms, bool persistent, const TimerCallback &callb } bool swoole_timer_del(TimerNode *tnode) { + if (!swoole_timer_is_available()) { + swWarn("timer is not available"); + return false; + } return SwooleTG.timer->remove(tnode); } void swoole_timer_delay(TimerNode *tnode, long delay_ms) { + if (!swoole_timer_is_available()) { + swWarn("timer is not available"); + return; + } return SwooleTG.timer->delay(tnode, delay_ms); } @@ -77,7 +85,7 @@ long swoole_timer_tick(long ms, const TimerCallback &callback, void *private_dat bool swoole_timer_exists(long timer_id) { if (!swoole_timer_is_available()) { - swWarn("timer[%ld] is not exists", timer_id); + swWarn("timer is not available"); return false; } TimerNode *tnode = SwooleTG.timer->get(timer_id); @@ -85,12 +93,16 @@ bool swoole_timer_exists(long timer_id) { } bool swoole_timer_clear(long timer_id) { + if (!swoole_timer_is_available()) { + swWarn("timer is not available"); + return false; + } return SwooleTG.timer->remove(SwooleTG.timer->get(timer_id)); } TimerNode *swoole_timer_get(long timer_id) { if (!swoole_timer_is_available()) { - swWarn("timer[%ld] is not exists", timer_id); + swWarn("timer is not available"); return nullptr; } return SwooleTG.timer->get(timer_id); @@ -98,6 +110,7 @@ TimerNode *swoole_timer_get(long timer_id) { void swoole_timer_free() { if (!swoole_timer_is_available()) { + swWarn("timer is not available"); return; } delete SwooleTG.timer; @@ -107,6 +120,7 @@ void swoole_timer_free() { int swoole_timer_select() { if (!swoole_timer_is_available()) { + swWarn("timer is not available"); return SW_ERR; } return SwooleTG.timer->select(); diff --git a/tests/swoole_runtime/curl_native/timer_coredump.phpt b/tests/swoole_runtime/curl_native/timer_coredump.phpt new file mode 100644 index 00000000000..0661008833a --- /dev/null +++ b/tests/swoole_runtime/curl_native/timer_coredump.phpt @@ -0,0 +1,34 @@ +--TEST-- +swoole_runtime/curl_native: timer coredump +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Done diff --git a/thirdparty/php/curl/curl_multi.h b/thirdparty/php/curl/curl_multi.h index 60347a51e5f..afc15737b18 100644 --- a/thirdparty/php/curl/curl_multi.h +++ b/thirdparty/php/curl/curl_multi.h @@ -95,7 +95,7 @@ class cURLMulti { } void del_timer() { - if (timer && swoole_event_is_available()) { + if (timer) { swoole_timer_del(timer); } }