diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index 5401b7a6fe6..fb514ba6931 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -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 {