From cec5cb3918ee29b6e0bd7f805c5b4f136bd7a872 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 5 Apr 1998 08:31:18 +0000 Subject: [PATCH] misc cleanup git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@780 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/QIFIO.c | 2 +- src/engine/Transaction.c | 33 ++++++++++++++++++++++----------- src/engine/Transaction.h | 7 +++++++ src/engine/TransactionP.h | 14 ++++++++++++-- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/engine/QIFIO.c b/src/engine/QIFIO.c index ac931a22fb..4c23399313 100644 --- a/src/engine/QIFIO.c +++ b/src/engine/QIFIO.c @@ -797,7 +797,7 @@ char * xaccReadQIFTransaction (int fd, Account *acc) * if we see something else, assume the worst, free the last * transaction, and return */ if ('!' == qifline[0]) { - xaccFreeTransaction (trans); + xaccTransDestroy (trans); return qifline; } diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 72ed9c0b8c..2d0b1d9890 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -319,17 +319,6 @@ xaccFreeTransaction( Transaction *trans ) if (!trans) return; - /* free a transaction only if it is not claimed - * by any accounts. */ - - i = 0; - s = trans->splits[i]; - while (s) { - if (s->acc) return; - i++; - s = trans->splits[i]; - } - /* free up the destination splits */ i = 0; s = trans->splits[i]; @@ -361,6 +350,28 @@ xaccFreeTransaction( Transaction *trans ) /********************************************************************\ \********************************************************************/ +void +xaccTransDestroy (Transaction *trans) +{ + int i; + Split *split; + + if (!trans) return; + + i=0; + split = trans->splits[i]; + while (split) { + xaccAccountRemoveSplit (split->acc, split); + i++; + split = trans->splits[i]; + } + + xaccFreeTransaction (trans); +} + +/********************************************************************\ +\********************************************************************/ + void xaccTransBeginEdit (Transaction *trans) { diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index 430c72657d..86ad17bcb0 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -64,6 +64,13 @@ typedef struct _transaction Transaction; Transaction * xaccMallocTransaction (void); /* mallocs and inits */ void xaccInitTransaction (Transaction *);/* clears a trans struct */ +/* The xaccTransactionDestroy() method will remove all + * of the splits from each of thier accounts, free the memory + * associated with them, and will then free the transaction + * itself. + */ +void xaccTransDestroy (Transaction *); + void xaccTransBeginEdit (Transaction *); void xaccTransCommitEdit (Transaction *); diff --git a/src/engine/TransactionP.h b/src/engine/TransactionP.h index 7d605e7ea2..88c8f09fda 100644 --- a/src/engine/TransactionP.h +++ b/src/engine/TransactionP.h @@ -105,10 +105,20 @@ struct _transaction }; -/* freeTransaction only does so if the transaction is not part of an - * account. (i.e. if none of the member splits are in an account). */ +/* The xaccFreeTransaction() method simply frees all memory associated + * with the transaction. It does not perform any consistency checks + * to verify that such freeing can be safely done. (e.g. id does + * not check to see if any of the member splits are referenced + * by an account. + */ void xaccFreeTransaction (Transaction *); +/* The xaccFreeSplit() method simply frees all memory associated + * with the split. It does not verify that the split isn't + * referenced in some account. If the split is referenced by an + * account, then calling this method will leave the system in an + * inconsistent state. + */ void xaccFreeSplit (Split *); /* frees memory */ /* The xaccTransRemoveSplit() routine will remove the indicated