From 3b7232c901f19c49451f5b4894d5c3be82c57d18 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 28 Apr 2006 23:29:18 +0000 Subject: Fix another watch remove bug --- common/glib-ectomy.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/common/glib-ectomy.c b/common/glib-ectomy.c index 16992e0f..45f9ce0d 100644 --- a/common/glib-ectomy.c +++ b/common/glib-ectomy.c @@ -143,7 +143,7 @@ guint g_io_add_watch_full(GIOChannel *channel, gint priority, watch->user_data = user_data; watch->destroy = notify; - watch->prev = 0; + watch->prev = &watch_head; watch->next = watch_head.next; if (watch_head.next) watch_head.next->prev = watch; @@ -296,17 +296,20 @@ void g_main_loop_run(GMainLoop *loop) if (rc < 0) continue; - for (w = watch_head.next; w; w = n) { - n = w->next; - if (*w->revents) { - gboolean keep = w->func(w->channel, *w->revents, w->user_data); - if (keep) - continue; - - if (w->destroy) - w->destroy(w->user_data); - watch_remove(w); + w = watch_head.next; + while (w) { + if (!*w->revents || w->func(w->channel, *w->revents, w->user_data)) { + w = w->next; + continue; } + + n = w->next; + + if (w->destroy) + w->destroy(w->user_data); + watch_remove(w); + + w = n; } /* check expired timers */ @@ -405,3 +408,5 @@ gint g_timeout_remove(const guint id) return -1; } + + -- cgit