Skip to content

Commit 9466a05

Browse files
fix: segmentation fault that was triggered when initializing a new timer and a reset was called at the same time (#11521)
This PR fixes a segmentation fault that was triggered when initializing a new timer and a reset was called at the same time.
1 parent 589dde0 commit 9466a05

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/runtime/uv/timer.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ extern "C" LEAN_EXPORT lean_obj_res lean_uv_timer_next(b_obj_arg obj) {
114114
auto setup_timer = [create_promise, obj, timer]() {
115115
lean_assert(timer->m_promise == NULL);
116116

117-
timer->m_promise = create_promise();
117+
lean_object* promise = create_promise();
118+
timer->m_promise = promise;
118119
timer->m_state = TIMER_STATE_RUNNING;
119120

120121
// The event loop must keep the timer alive for the duration of the run time.
121122
lean_inc(obj);
123+
lean_inc(promise);
122124

123125
int result = uv_timer_start(
124126
timer->m_uv_timer,
@@ -127,15 +129,15 @@ extern "C" LEAN_EXPORT lean_obj_res lean_uv_timer_next(b_obj_arg obj) {
127129
timer->m_repeating ? timer->m_timeout : 0
128130
);
129131

130-
event_loop_unlock(&global_ev);
131-
132132
if (result != 0) {
133133
lean_dec(obj);
134+
event_loop_unlock(&global_ev);
134135
return lean_io_result_mk_error(lean_decode_uv_error(result, NULL));
135-
} else {
136-
lean_inc(timer->m_promise);
137-
return lean_io_result_mk_ok(timer->m_promise);
138136
}
137+
138+
event_loop_unlock(&global_ev);
139+
140+
return lean_io_result_mk_ok(promise);
139141
};
140142

141143
event_loop_lock(&global_ev);

0 commit comments

Comments
 (0)