[Gnucash-changes] r13152 - gnucash/trunk/lib/libqof/qof - Don't allow the event handler list to shrink while we're traversing it.

Chris Shoemaker chris at cvs.gnucash.org
Wed Feb 8 01:04:51 EST 2006


Author: chris
Date: 2006-02-08 01:04:51 -0500 (Wed, 08 Feb 2006)
New Revision: 13152
Trac: http://svn.gnucash.org/trac/changeset/13152

Modified:
   gnucash/trunk/lib/libqof/qof/gnc-event.c
Log:
   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.


Modified: gnucash/trunk/lib/libqof/qof/gnc-event.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-event.c	2006-02-08 06:00:36 UTC (rev 13151)
+++ gnucash/trunk/lib/libqof/qof/gnc-event.c	2006-02-08 06:04:51 UTC (rev 13152)
@@ -108,15 +108,19 @@
     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;
   }



More information about the gnucash-changes mailing list