Prevent the deadlock issue by copying lists 53/315653/3
authorInhong Han <inhong1.han@samsung.com>
Tue, 6 Aug 2024 00:36:11 +0000 (09:36 +0900)
committerInhong Han <inhong1.han@samsung.com>
Tue, 6 Aug 2024 04:32:03 +0000 (13:32 +0900)
Change-Id: I88c5801071642f9f042250121b99933daea9cd9b

src/bin/e_input_event.c

index 90d6a085afea1f9e9214b5b8257a66ada53ec4df..f8a8817e9c316ea166ce2b620cc00acf38b8d9a5 100755 (executable)
@@ -173,7 +173,7 @@ e_input_event_filter_del(E_Input_Event_Source *source, E_Input_Event_Filter *eve
 static gboolean
 _process_filter_event(E_Input_Event_Source *ev_source, E_Input_Event *ev)
 {
-   GList *l;
+   GList *l, *clone;
    E_Input_Event_Filter *ef;
    void *data;
 
@@ -181,9 +181,12 @@ _process_filter_event(E_Input_Event_Source *ev_source, E_Input_Event *ev)
 
    g_rec_mutex_lock(&ev_source->ev_filter_mutex);
    l = ev_source->ev_filter_list;
-   while (l)
+   clone = g_list_copy(l);
+   g_rec_mutex_unlock(&ev_source->ev_filter_mutex);
+
+   for(GList *list = g_list_first(clone); list; list = list->next)
      {
-        data = l->data;
+        data = list->data;
         ef = (E_Input_Event_Filter *)data;
         if (ef && ef->event == ev->event_type)
           {
@@ -191,15 +194,19 @@ _process_filter_event(E_Input_Event_Source *ev_source, E_Input_Event *ev)
                {
                   if (ef->func(ef->user_data, ef->event, ev->ev_data) == FALSE)
                     {
-                       g_rec_mutex_unlock(&ev_source->ev_filter_mutex);
+                       g_list_free(clone);
+                       clone = NULL;
                        return FALSE;
                     }
                }
           }
+     }
 
-        l = g_list_next(l);
+   if (clone)
+     {
+        g_list_free(clone);
+        clone = NULL;
      }
-   g_rec_mutex_unlock(&ev_source->ev_filter_mutex);
 
    return TRUE;
 }
@@ -207,7 +214,7 @@ _process_filter_event(E_Input_Event_Source *ev_source, E_Input_Event *ev)
 static gboolean
 _process_event_handler(E_Input_Event_Source *ev_source, E_Input_Event *ev)
 {
-   GList *l;
+   GList *l, *clone;
    E_Input_Event_Handler *eh = NULL;
    void *data;
 
@@ -215,9 +222,12 @@ _process_event_handler(E_Input_Event_Source *ev_source, E_Input_Event *ev)
 
    g_rec_mutex_lock(&ev_source->ev_handler_mutex);
    l = ev_source->ev_handler_list;
-   while (l)
+   clone = g_list_copy(l);
+   g_rec_mutex_unlock(&ev_source->ev_handler_mutex);
+
+   for(GList *list = g_list_first(clone); list; list = list->next)
      {
-        data = l->data;
+        data = list->data;
         if (!data)
           continue;
 
@@ -228,15 +238,19 @@ _process_event_handler(E_Input_Event_Source *ev_source, E_Input_Event *ev)
                {
                   if (eh->func(eh->user_data, eh->event, ev->ev_data) == FALSE)
                     {
-                       g_rec_mutex_unlock(&ev_source->ev_handler_mutex);
+                       g_list_free(clone);
+                       clone = NULL;
                        return FALSE;
                     }
                }
           }
+     }
 
-        l = g_list_next(l);
+   if (clone)
+     {
+        g_list_free(clone);
+        clone = NULL;
      }
-   g_rec_mutex_unlock(&ev_source->ev_handler_mutex);
 
    return TRUE;
 }