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>
|
2004-05-24 Derek Atkins <derek@ihtfp.com>
|
||||||
|
|
||||||
* src/report/standard-reports/transaction.cm: applied Vasil's
|
* src/report/standard-reports/transaction.cm: applied Vasil's
|
||||||
|
|||||||
@@ -1463,6 +1463,9 @@ xaccTransBeginEdit (Transaction *trans)
|
|||||||
{
|
{
|
||||||
GNC_BEGIN_EDIT(&trans->inst)
|
GNC_BEGIN_EDIT(&trans->inst)
|
||||||
|
|
||||||
|
if (qof_book_shutting_down(trans->inst.book))
|
||||||
|
return;
|
||||||
|
|
||||||
xaccOpenLog ();
|
xaccOpenLog ();
|
||||||
xaccTransWriteLog (trans, 'B');
|
xaccTransWriteLog (trans, 'B');
|
||||||
|
|
||||||
@@ -1481,7 +1484,8 @@ xaccTransDestroy (Transaction *trans)
|
|||||||
if (!trans) return;
|
if (!trans) return;
|
||||||
check_open (trans);
|
check_open (trans);
|
||||||
|
|
||||||
if (xaccTransGetReadOnly (trans)) return;
|
if (xaccTransGetReadOnly (trans) &&
|
||||||
|
!qof_book_shutting_down(trans->inst.book)) return;
|
||||||
|
|
||||||
trans->inst.do_free = TRUE;
|
trans->inst.do_free = TRUE;
|
||||||
}
|
}
|
||||||
@@ -1509,13 +1513,17 @@ static void
|
|||||||
do_destroy (Transaction *trans)
|
do_destroy (Transaction *trans)
|
||||||
{
|
{
|
||||||
SplitList *node;
|
SplitList *node;
|
||||||
|
gboolean shutting_down;
|
||||||
|
|
||||||
/* If there are capital-gains transactions associated with this,
|
/* If there are capital-gains transactions associated with this,
|
||||||
* they need to be destroyed too. */
|
* they need to be destroyed too. */
|
||||||
destroy_gains (trans);
|
destroy_gains (trans);
|
||||||
|
|
||||||
|
shutting_down = qof_book_shutting_down(trans->inst.book);
|
||||||
|
|
||||||
/* Make a log in the journal before destruction. */
|
/* 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);
|
gnc_engine_gen_event (&trans->inst.entity, GNC_EVENT_DESTROY);
|
||||||
|
|
||||||
@@ -1525,7 +1533,8 @@ do_destroy (Transaction *trans)
|
|||||||
|
|
||||||
mark_split (split);
|
mark_split (split);
|
||||||
xaccAccountRemoveSplit (split->acc, split);
|
xaccAccountRemoveSplit (split->acc, split);
|
||||||
xaccAccountRecomputeBalance (split->acc);
|
if (!shutting_down)
|
||||||
|
xaccAccountRecomputeBalance (split->acc);
|
||||||
gen_event (split);
|
gen_event (split);
|
||||||
xaccFreeSplit (split);
|
xaccFreeSplit (split);
|
||||||
|
|
||||||
@@ -1952,7 +1961,15 @@ xaccSplitDestroy (Split *split)
|
|||||||
|
|
||||||
/* Note: split is removed from lot when its removed from accoount */
|
/* Note: split is removed from lot when its removed from accoount */
|
||||||
xaccAccountRemoveSplit (acc, split);
|
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);
|
gen_event (split);
|
||||||
xaccFreeSplit (split);
|
xaccFreeSplit (split);
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ struct _QofBook
|
|||||||
* but has not yet been written out to storage (file/database)
|
* but has not yet been written out to storage (file/database)
|
||||||
*/
|
*/
|
||||||
gboolean dirty;
|
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 */
|
/** version number, used for tracking multiuser updates */
|
||||||
gint32 version;
|
gint32 version;
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ qof_book_destroy (QofBook *book)
|
|||||||
{
|
{
|
||||||
if (!book) return;
|
if (!book) return;
|
||||||
|
|
||||||
|
book->shutting_down = TRUE;
|
||||||
|
|
||||||
ENTER ("book=%p", book);
|
ENTER ("book=%p", book);
|
||||||
gnc_engine_force_event (&book->entity, GNC_EVENT_DESTROY);
|
gnc_engine_force_event (&book->entity, GNC_EVENT_DESTROY);
|
||||||
|
|
||||||
@@ -171,6 +173,13 @@ qof_book_get_backend (QofBook *book)
|
|||||||
return book->backend;
|
return book->backend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
qof_book_shutting_down (QofBook *book)
|
||||||
|
{
|
||||||
|
if (!book) return FALSE;
|
||||||
|
return book->shutting_down;
|
||||||
|
}
|
||||||
|
|
||||||
/* ====================================================================== */
|
/* ====================================================================== */
|
||||||
/* setters */
|
/* setters */
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,9 @@ QofBackend *qof_book_get_backend (QofBook *book);
|
|||||||
|
|
||||||
void qof_book_set_backend (QofBook *book, QofBackend *);
|
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
|
/** qof_book_not_saved() will return TRUE if any
|
||||||
* data in the book hasn't been saved to long-term storage.
|
* data in the book hasn't been saved to long-term storage.
|
||||||
* (Actually, that's not quite true. The book doesn't know
|
* (Actually, that's not quite true. The book doesn't know
|
||||||
|
|||||||
Reference in New Issue
Block a user