Bug 799389 - Crash when removing an account

Destroying the split vector from front->back crashes halfway through
because the iterators aren't updated as we remove items from the
vector. Iterating in reverse works because the remaining elements
aren't moved as we delete.
This commit is contained in:
John Ralls
2024-08-19 12:39:07 -07:00
parent 436889b455
commit 514793d7a0

View File

@@ -1546,8 +1546,9 @@ xaccAccountCommitEdit (Account *acc)
themselves will be destroyed by the transaction code */
if (!qof_book_shutting_down(book))
{
for (auto s : priv->splits)
xaccSplitDestroy (s);
// We need to delete in reverse order so that the vector's iterators aren't invalidated.
for_each(priv->splits.rbegin(), priv->splits.rend(), [](Split *s) {
xaccSplitDestroy (s); });
}
else
{