Skip to content

Commit

Permalink
Bug 799389 - Crash when removing an account
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jralls committed Aug 19, 2024
1 parent 436889b commit 514793d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libgnucash/engine/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 514793d

Please sign in to comment.