Skip to content

Commit 836e6a3

Browse files
committed
Adjust object ref count after call to ev_timer_again
1 parent 177de8f commit 836e6a3

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/node_timer.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,22 @@ Handle<Value> Timer::Again(const Arguments& args) {
147147
HandleScope scope;
148148
Timer *timer = ObjectWrap::Unwrap<Timer>(args.Holder());
149149

150+
int was_active = ev_is_active(&timer->watcher_);
151+
150152
ev_tstamp repeat = NODE_V8_UNIXTIME(args[0]);
151153
if (repeat > 0) timer->watcher_.repeat = repeat;
154+
152155
ev_timer_again(EV_DEFAULT_UC_ &timer->watcher_);
153156

157+
// ev_timer_again can start or stop the watcher.
158+
// So we need to check what happened and adjust the ref count
159+
// appropriately.
160+
161+
if (ev_is_active(&timer->watcher_)) {
162+
if (!was_active) timer->Ref();
163+
} else {
164+
if (was_active) timer->Unref();
165+
}
166+
154167
return Undefined();
155168
}

0 commit comments

Comments
 (0)