Bug 799528 - Crash on account deletion (edit)

New function xaccAccountDeleteAllTransactions.

Delete all transactions before deleting the account; simply deleting the
splits during account destruction isn't safe. In the particular case of an
imbalance account the transaction commit after deleting a split just makes
a new one.
pull/2061/head
John Ralls 1 year ago
parent f3b08ddefb
commit bc7fafd4ad

@ -1694,11 +1694,22 @@ do_delete_account (Account* account, Account* saa, Account* sta, Account* ta)
(AccountCb)xaccAccountMoveAllSplits,
sta);
}
else
{
gnc_account_foreach_descendant (account,
[](auto acc, [[maybe_unused]] auto data)
{ xaccAccountDestroyAllTransactions(acc); },
nullptr);
}
if (ta)
{
/* Move the splits of the account to be deleted. */
xaccAccountMoveAllSplits (account, ta);
}
else
{
xaccAccountDestroyAllTransactions (account);
}
xaccAccountCommitEdit (account);
/* Drop all references from the state file for

@ -49,6 +49,7 @@
#include <numeric>
#include <map>
#include <unordered_set>
#include <algorithm>
static QofLogModule log_module = GNC_MOD_ACCOUNT;
@ -1596,6 +1597,18 @@ xaccAccountDestroy (Account *acc)
xaccAccountCommitEdit (acc);
}
void
xaccAccountDestroyAllTransactions(Account *acc)
{
auto priv = GET_PRIVATE(acc);
std::vector<Transaction*> transactions;
std::transform(priv->splits.begin(), priv->splits.end(),
back_inserter(transactions),
[](auto split) { return split->parent; });
std::for_each(transactions.rbegin(), transactions.rend(),
[](auto trans) { xaccTransDestroy (trans); });
}
/********************************************************************\
\********************************************************************/

@ -210,6 +210,10 @@ typedef enum
* (by calling xaccAccountBeginEdit()) before calling this routine.*/
void xaccAccountDestroy (Account *account);
/** Destroy all of the transactions that parent splits in an account.
*/
void xaccAccountDestroyAllTransactions(Account *acc);
/** Compare two accounts for equality - this is a deep compare. */
gboolean xaccAccountEqual(const Account *a, const Account* b,
gboolean check_guids);

Loading…
Cancel
Save