Book Closing in HEAD kills objects in a "bad" order, corrupts memory.

Derek Atkins warlord at MIT.EDU
Tue May 25 11:52:08 EDT 2004

I'm not 100% convinced it's the order that matters...  I'm thinking
that during book_end() the various objects should just free() themselves
of memory and not worry about keeping themselves balanced.  In other

        if (qof_book_is_ending(book)) {

This will certainly fix the symtom of shutdown order without having to
determine a concise module begin/end ordering.  The downside of this
approach is an extra function call for every Destroy operation, but
how often does that happen?  Besides, the one extra function call is
certainly cheaper than all the extra function calls and math
operations that take place unnecessarily.


Josh Sled <jsled at> writes:

> On Tue, 2004-05-25 at 10:33, Derek Atkins wrote:
>> I instrumented qof_object_book_end to print out the object it was
>> closing out (not included in the patch below).  As you can see, it's
>> closing out the CommodityTable before the AccountGroup, which is bad.
> Seems like that list of things-to-destroy needs to be in the right
> order... or we need to introduce reference-counting...
>> As you can see from the following trace this causes a memory access
>> failure because transactions are kept in balance even when we're
>> destroying the book, so it's trying to scrub against an
>> already-destroyed commodity.
> Why do we need to scrub things we're just trying to get rid of?  It
> seems like the scrubbing is best conditional on how the destruction in
> coming about.
>> DEBUG: Enter: qof_object_book_end
>> DEBUG: Debug: qof_object_book_end(): Closing CommodityTable
>> DEBUG: Debug: qof_object_book_end(): Closing Price
>> DEBUG: Debug: qof_object_book_end(): Closing Scheduled Transaction Templates
>> DEBUG: Debug: qof_object_book_end(): Closing AccountGroup
> What should the order be...?  I'm thinking...
> * Business objects / SX templates
> * Splits / Transactions
> * Accounts / Price-DB
> * Commodities / Lots [?]
> * Session state [?]
> * Book
> ?
> ...jsled
> ________________________________________________________________________
> -- 
> - `a=jsled;; echo ${a}@${b}`

       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL:    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available

More information about the gnucash-devel mailing list