mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
14
ChangeLog
14
ChangeLog
@@ -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
|
||||
|
||||
@@ -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,12 +1513,16 @@ 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. */
|
||||
if (! shutting_down)
|
||||
xaccTransWriteLog (trans, 'D');
|
||||
|
||||
gnc_engine_gen_event (&trans->inst.entity, GNC_EVENT_DESTROY);
|
||||
@@ -1525,6 +1533,7 @@ do_destroy (Transaction *trans)
|
||||
|
||||
mark_split (split);
|
||||
xaccAccountRemoveSplit (split->acc, split);
|
||||
if (!shutting_down)
|
||||
xaccAccountRecomputeBalance (split->acc);
|
||||
gen_event (split);
|
||||
xaccFreeSplit (split);
|
||||
@@ -1952,8 +1961,16 @@ xaccSplitDestroy (Split *split)
|
||||
|
||||
/* Note: split is removed from lot when its removed from accoount */
|
||||
xaccAccountRemoveSplit (acc, split);
|
||||
|
||||
/* 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);
|
||||
return TRUE;
|
||||
|
||||
@@ -72,6 +72,12 @@ struct _QofBook
|
||||
*/
|
||||
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;
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user