diff --git a/src/engine/Account.c b/src/engine/Account.c index 55541d27f4..36483b2532 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -124,26 +124,21 @@ xaccFreeAccount( Account *acc ) if (acc->security) free (acc->security); /* any split pointing at this account needs to be unmarked */ - i=0; - s = acc->splits[0]; - while (s) { - s->acc = NULL; - i++; + for (i=0; inumSplits; i++) { s = acc->splits[i]; + s->acc = NULL; } /* search for orphaned transactions, and delete them */ - i=0; - s = acc->splits[0]; - while (s) { - xaccSplitDestroy (s); - i++; + for (i=0; inumSplits; i++) { s = acc->splits[i]; + xaccSplitDestroy (s); } /* free up array of split pointers */ _free (acc->splits); acc->splits = NULL; + acc->numSplits = 0; /* zero out values, just in case stray * pointers are pointing here. */ diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 1e3b1a20f3..cb1c6150fa 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -749,13 +749,12 @@ xaccSplitDestroy (Split *split) trans = split->parent; assert (trans); assert (trans->splits); - CHECK_OPEN (trans); + // temp hack alert -- get rid of annoying error messages + // CHECK_OPEN (trans); numsplits = 0; s = trans->splits[0]; while (s) { -/* xxxxxxx */ -printf ("SplitDestroy(): trans=%p, %d'th split=%p\n", trans, numsplits, s); MARK_SPLIT(s); if (s == split) ismember = 1; numsplits ++; @@ -763,10 +762,17 @@ printf ("SplitDestroy(): trans=%p, %d'th split=%p\n", trans, numsplits, s); } assert (ismember); - /* if the account has three or more splits, + /* If the account has three or more splits, + * merely unlink & free the split. + * + * Or if the account has only two splits, and the + * split to be destroyed is a price split (i.e. + * has a damount value of zero), then * merely unlink & free the split. */ - if (2 < numsplits) { + if ((2 < numsplits) || + ((2 == numsplits) && (DEQ(0.0, split->damount)))) + { MARK_SPLIT (split); xaccTransRemoveSplit (trans, split); acc = split->acc;