From 836e6a3fcbe297fb22edfda521c3e6ea540b59e5 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 12 Mar 2010 12:27:41 -0800 Subject: [PATCH] Adjust object ref count after call to ev_timer_again --- src/node_timer.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/node_timer.cc b/src/node_timer.cc index b1b6d35261a..1a3ed791d3d 100644 --- a/src/node_timer.cc +++ b/src/node_timer.cc @@ -147,9 +147,22 @@ Handle Timer::Again(const Arguments& args) { HandleScope scope; Timer *timer = ObjectWrap::Unwrap(args.Holder()); + int was_active = ev_is_active(&timer->watcher_); + ev_tstamp repeat = NODE_V8_UNIXTIME(args[0]); if (repeat > 0) timer->watcher_.repeat = repeat; + ev_timer_again(EV_DEFAULT_UC_ &timer->watcher_); + // ev_timer_again can start or stop the watcher. + // So we need to check what happened and adjust the ref count + // appropriately. + + if (ev_is_active(&timer->watcher_)) { + if (!was_active) timer->Ref(); + } else { + if (was_active) timer->Unref(); + } + return Undefined(); }