Fix wrong gsource deletion 26/294526/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 20 Jun 2023 23:49:54 +0000 (23:49 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 20 Jun 2023 23:49:54 +0000 (23:49 +0000)
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 <h.jhun@samsung.com>
src/aul_worker.c

index 8c58feb..09fc786 100644 (file)
@@ -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;
        }