From 943532c8cd782e2ec292aa298035635ee633f843 Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Wed, 8 Feb 2006 06:04:51 +0000 Subject: [PATCH] Don't allow the event handler list to shrink while we're traversing it. This change isn't ideal in the sense that the handler list is now a monotonically increasing resource, but it's better than crashing when the handler in node N+1 happens to be deleted while servicing the handler in node N. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13152 57a11ea4-9604-0410-9ed3-97b8803252fd --- lib/libqof/qof/gnc-event.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/libqof/qof/gnc-event.c b/lib/libqof/qof/gnc-event.c index 7b82fc0c7f..26d98d384e 100644 --- a/lib/libqof/qof/gnc-event.c +++ b/lib/libqof/qof/gnc-event.c @@ -108,15 +108,19 @@ gnc_engine_unregister_event_handler (gint handler_id) if (hi->handler_id != handler_id) continue; - /* Found it, take out of list */ - handlers = g_list_remove_link (handlers, node); + /* Normally, we could actually remove the handler's node from the + list, but we may be unregistering the event handler as a result + of a generated event, such as GNC_EVENT_DESTROY. In that case, + we're in the middle of walking the GList and it is wrong to + modify the list. So, instead, we just NULL the handler. */ + /* handlers = g_list_remove_link (handlers, node); */ LEAVE ("(handler_id=%d) handler=%p data=%p", handler_id, hi->handler, hi->user_data); /* safety */ hi->handler = NULL; - g_list_free_1 (node); - g_free (hi); + /* g_list_free_1 (node); + g_free (hi); */ return; }