From c7545932d4d4b750ae29a578fb9b70824d7da493 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 20 Jun 2023 23:49:54 +0000 Subject: [PATCH] Fix wrong gsource deletion While terminating the worker thread, the worker thread tries to remove the anr timer source. In this time, the g_source_remove() was called. It makes an error. This patch uses the g_source_destroy() instead of the g_source_remove(). Before calling the g_source_destroy(), the worker finds the source using the source id with the GMainContext. Change-Id: Iee25a57b0b9036d028c0974187f013eb3e99b864 Signed-off-by: Hwankyu Jhun --- src/aul_worker.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/aul_worker.c b/src/aul_worker.c index 8c58feb..09fc786 100644 --- a/src/aul_worker.c +++ b/src/aul_worker.c @@ -380,8 +380,14 @@ static gpointer __worker_thread_loop(gpointer data) g_main_loop_run(worker->loop); g_mutex_lock(&worker->mutex); - if (anr_timer->tag) - g_source_remove(anr_timer->tag); + if (anr_timer->tag) { + source = g_main_context_find_source_by_id(worker->context, + anr_timer->tag); + if (source && !g_source_is_destroyed(source)) + g_source_destroy(source); + + anr_timer->tag = 0; + } g_list_free_full(worker->jobs, __destroy_job); g_main_context_pop_thread_default(worker->context); @@ -556,7 +562,9 @@ int aul_worker_remove_anr_timer(aul_worker_h handle) if (anr_timer->tag) { source = g_main_context_find_source_by_id(worker->context, anr_timer->tag); - g_source_destroy(source); + if (source && !g_source_is_destroyed(source)) + g_source_destroy(source); + anr_timer->tag = 0; anr_timer->start_time = 0; } -- 2.7.4