fd-handler: Fix a bug caused by wrong context 75/313675/2 accepted/tizen/7.0/unified/20240701.174514
authorUnsung Lee <unsung.lee@samsung.com>
Sun, 30 Jun 2024 11:30:53 +0000 (20:30 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Mon, 1 Jul 2024 02:52:51 +0000 (11:52 +0900)
Fix a bug caused by wrong context in the g_source_remove().
g_source_remove() assumes default main context, but some
gsource are attached to the specific context instead of
default main context.
In conclusion, find the gsource from each context first before
freeing source.

Change-Id: I8ec20108750a28ce1c7a4a5d829f0a1842ab4baa
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/common/fd-handler.c

index 8e5b913..bb40b8d 100644 (file)
@@ -39,6 +39,7 @@ struct fd_handler_s {
        void *data;
        release_cb free_func;
        fd_handler_h *handler_p;
+       GMainContext *context;
 };
 
 int remove_fd_read_handler(fd_handler_h *handler)
@@ -53,8 +54,11 @@ int remove_fd_read_handler(fd_handler_h *handler)
        if (h->free_func)
                h->free_func(h->data);
 
-       if (h->id)
-               g_source_remove(h->id);
+       if (h->id) {
+               GSource *source = g_main_context_find_source_by_id (h->context, h->id);
+               if (source)
+                       g_source_destroy(source);
+       }
 
        if (h->ch)
                g_io_channel_unref(h->ch);
@@ -150,6 +154,7 @@ int add_fd_read_handler(GMainContext *context, int fd,
        h->ch = ch;
        h->id = id;
        h->handler_p = handler;
+       h->context = context;
        if (handler != NULL)
                *handler = h;