[Gnucash-changes] Fix memory corruption: add book_closing and use
it.
Derek Atkins
warlord at cvs.gnucash.org
Sat May 29 13:45:58 EDT 2004
Log Message:
-----------
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.
Modified Files:
--------------
gnucash:
ChangeLog
gnucash/src/engine:
Transaction.c
qofbook-p.h
qofbook.c
qofbook.h
Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1814
retrieving revision 1.1815
diff -LChangeLog -LChangeLog -u -r1.1814 -r1.1815
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,17 @@
+2004-05-29 Derek Atkins <derek at 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 at ihtfp.com>
* src/report/standard-reports/transaction.cm: applied Vasil's
Index: Transaction.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Transaction.c,v
retrieving revision 1.307
retrieving revision 1.308
diff -Lsrc/engine/Transaction.c -Lsrc/engine/Transaction.c -u -r1.307 -r1.308
--- src/engine/Transaction.c
+++ src/engine/Transaction.c
@@ -1463,6 +1463,9 @@
{
GNC_BEGIN_EDIT(&trans->inst)
+ if (qof_book_shutting_down(trans->inst.book))
+ return;
+
xaccOpenLog ();
xaccTransWriteLog (trans, 'B');
@@ -1481,7 +1484,8 @@
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 @@
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 @@
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 @@
/* 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);
Index: qofbook.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofbook.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lsrc/engine/qofbook.h -Lsrc/engine/qofbook.h -u -r1.11 -r1.12
--- src/engine/qofbook.h
+++ src/engine/qofbook.h
@@ -111,6 +111,9 @@
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
Index: qofbook.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofbook.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -Lsrc/engine/qofbook.c -Lsrc/engine/qofbook.c -u -r1.21 -r1.22
--- src/engine/qofbook.c
+++ src/engine/qofbook.c
@@ -103,6 +103,8 @@
{
if (!book) return;
+ book->shutting_down = TRUE;
+
ENTER ("book=%p", book);
gnc_engine_force_event (&book->entity, GNC_EVENT_DESTROY);
@@ -171,6 +173,13 @@
return book->backend;
}
+gboolean
+qof_book_shutting_down (QofBook *book)
+{
+ if (!book) return FALSE;
+ return book->shutting_down;
+}
+
/* ====================================================================== */
/* setters */
Index: qofbook-p.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofbook-p.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lsrc/engine/qofbook-p.h -Lsrc/engine/qofbook-p.h -u -r1.6 -r1.7
--- src/engine/qofbook-p.h
+++ src/engine/qofbook-p.h
@@ -71,6 +71,12 @@
* 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;
More information about the gnucash-changes
mailing list