Fix memory corruption: add book_closing and use it.

* src/engine/Transaction.c:
	  Don't recompute balances or write to the translog when we're
	  shutting down.  Destroy the parent transaction from xaccSplitDestroy()
	  if we're shutting down.
	* src/engine/qofbook-p.h:
	* src/engine/qofbook.h:
	* src/engine/qofbook.c:
	  add "shutting_down" parameter and getter-method, so that
	  objects can detect when the book is shutting down and
	  ignore non-necessary reprocessing.  Fixes a memory corruption
	  bug during book-closing.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9972 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2004-05-29 17:45:56 +00:00
parent b83705a471
commit a9bbb453e7
5 changed files with 53 additions and 4 deletions

View File

@@ -1,3 +1,17 @@
2004-05-29 Derek Atkins <derek@ihtfp.com>
* src/engine/Transaction.c:
Don't recompute balances or write to the translog when we're
shutting down. Destroy the parent transaction from xaccSplitDestroy()
if we're shutting down.
* src/engine/qofbook-p.h:
* src/engine/qofbook.h:
* src/engine/qofbook.c:
add "shutting_down" parameter and getter-method, so that
objects can detect when the book is shutting down and
ignore non-necessary reprocessing. Fixes a memory corruption
bug during book-closing.
2004-05-24 Derek Atkins <derek@ihtfp.com>
* src/report/standard-reports/transaction.cm: applied Vasil's

View File

@@ -1463,6 +1463,9 @@ xaccTransBeginEdit (Transaction *trans)
{
GNC_BEGIN_EDIT(&trans->inst)
if (qof_book_shutting_down(trans->inst.book))
return;
xaccOpenLog ();
xaccTransWriteLog (trans, 'B');
@@ -1481,7 +1484,8 @@ xaccTransDestroy (Transaction *trans)
if (!trans) return;
check_open (trans);
if (xaccTransGetReadOnly (trans)) return;
if (xaccTransGetReadOnly (trans) &&
!qof_book_shutting_down(trans->inst.book)) return;
trans->inst.do_free = TRUE;
}
@@ -1509,13 +1513,17 @@ static void
do_destroy (Transaction *trans)
{
SplitList *node;
gboolean shutting_down;
/* If there are capital-gains transactions associated with this,
* they need to be destroyed too. */
destroy_gains (trans);
shutting_down = qof_book_shutting_down(trans->inst.book);
/* Make a log in the journal before destruction. */
xaccTransWriteLog (trans, 'D');
if (! shutting_down)
xaccTransWriteLog (trans, 'D');
gnc_engine_gen_event (&trans->inst.entity, GNC_EVENT_DESTROY);
@@ -1525,7 +1533,8 @@ do_destroy (Transaction *trans)
mark_split (split);
xaccAccountRemoveSplit (split->acc, split);
xaccAccountRecomputeBalance (split->acc);
if (!shutting_down)
xaccAccountRecomputeBalance (split->acc);
gen_event (split);
xaccFreeSplit (split);
@@ -1952,7 +1961,15 @@ xaccSplitDestroy (Split *split)
/* Note: split is removed from lot when its removed from accoount */
xaccAccountRemoveSplit (acc, split);
xaccAccountRecomputeBalance (acc);
/* If we're shutting down then destroy the transaction, too, and
* don't recompute the balance.
*/
if (qof_book_shutting_down (split->parent->inst.book))
xaccTransDestroy (trans);
else
xaccAccountRecomputeBalance (acc);
gen_event (split);
xaccFreeSplit (split);

View File

@@ -71,6 +71,12 @@ struct _QofBook
* but has not yet been written out to storage (file/database)
*/
gboolean dirty;
/** a flag denoting whether the book is closing down, used to
* help the QOF objects shut down cleanly without maintaining
* internal consistency.
*/
gboolean shutting_down;
/** version number, used for tracking multiuser updates */
gint32 version;

View File

@@ -103,6 +103,8 @@ qof_book_destroy (QofBook *book)
{
if (!book) return;
book->shutting_down = TRUE;
ENTER ("book=%p", book);
gnc_engine_force_event (&book->entity, GNC_EVENT_DESTROY);
@@ -171,6 +173,13 @@ qof_book_get_backend (QofBook *book)
return book->backend;
}
gboolean
qof_book_shutting_down (QofBook *book)
{
if (!book) return FALSE;
return book->shutting_down;
}
/* ====================================================================== */
/* setters */

View File

@@ -111,6 +111,9 @@ QofBackend *qof_book_get_backend (QofBook *book);
void qof_book_set_backend (QofBook *book, QofBackend *);
/** Is the book shutting down? */
gboolean qof_book_shutting_down (QofBook *book);
/** qof_book_not_saved() will return TRUE if any
* data in the book hasn't been saved to long-term storage.
* (Actually, that's not quite true. The book doesn't know