ssb: Fix a timer leak I observed trying to wrap up 0.0.24.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 17m17s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 17m17s
This commit is contained in:
parent
32a335c676
commit
9614d03bef
32
src/ssb.c
32
src/ssb.c
@ -2450,6 +2450,20 @@ static void _tf_ssb_on_handle_close(uv_handle_t* handle)
|
||||
|
||||
static void _tf_ssb_on_timer_close(uv_handle_t* handle)
|
||||
{
|
||||
tf_ssb_timer_t* timer = handle->data;
|
||||
for (int i = 0; i < timer->ssb->timers_count; i++)
|
||||
{
|
||||
if (timer->ssb->timers[i] == timer)
|
||||
{
|
||||
timer->ssb->timers[i] = timer->ssb->timers[--timer->ssb->timers_count];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (timer->ssb->shutting_down && !timer->ssb->timers_count)
|
||||
{
|
||||
tf_free(timer->ssb->timers);
|
||||
timer->ssb->timers = NULL;
|
||||
}
|
||||
tf_free(handle->data);
|
||||
}
|
||||
|
||||
@ -2503,14 +2517,11 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
|
||||
{
|
||||
uv_close((uv_handle_t*)&ssb->timers[i]->timer, _tf_ssb_on_timer_close);
|
||||
}
|
||||
ssb->timers_count = 0;
|
||||
tf_free(ssb->timers);
|
||||
ssb->timers = NULL;
|
||||
|
||||
tf_printf("Waiting for closes.\n");
|
||||
|
||||
while (ssb->broadcast_listener.data || ssb->broadcast_sender.data || ssb->broadcast_timer.data || ssb->broadcast_cleanup_timer.data || ssb->trace_timer.data ||
|
||||
ssb->server.data || ssb->ref_count || ssb->request_activity_timer.data)
|
||||
ssb->server.data || ssb->ref_count || ssb->request_activity_timer.data || ssb->timers_count)
|
||||
{
|
||||
uv_run(ssb->loop, UV_RUN_ONCE);
|
||||
}
|
||||
@ -4197,19 +4208,16 @@ static void _tf_ssb_scheduled_timer(uv_timer_t* handle)
|
||||
{
|
||||
tf_ssb_timer_t* timer = handle->data;
|
||||
timer->callback(timer->ssb, timer->user_data);
|
||||
for (int i = 0; i < timer->ssb->timers_count; i++)
|
||||
{
|
||||
if (timer->ssb->timers[i] == timer)
|
||||
{
|
||||
timer->ssb->timers[i] = timer->ssb->timers[--timer->ssb->timers_count];
|
||||
break;
|
||||
}
|
||||
}
|
||||
uv_close((uv_handle_t*)handle, _tf_ssb_on_timer_close);
|
||||
}
|
||||
|
||||
void tf_ssb_schedule_work(tf_ssb_t* ssb, int delay_ms, void (*callback)(tf_ssb_t* ssb, void* user_data), void* user_data)
|
||||
{
|
||||
if (ssb->shutting_down)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ssb->timers = tf_resize_vec(ssb->timers, sizeof(uv_timer_t*) * (ssb->timers_count + 1));
|
||||
tf_ssb_timer_t* timer = tf_malloc(sizeof(tf_ssb_timer_t));
|
||||
*timer = (tf_ssb_timer_t)
|
||||
|
Loading…
Reference in New Issue
Block a user