gnucash stable: Bug 799389 - Crash when removing an account

John Ralls jralls at code.gnucash.org
Mon Aug 19 15:59:31 EDT 2024


Updated	 via  https://github.com/Gnucash/gnucash/commit/514793d7 (commit)
	from  https://github.com/Gnucash/gnucash/commit/436889b4 (commit)



commit 514793d7a0a8d057717d2a734de82a1d030a81d3
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Aug 19 12:39:07 2024 -0700

    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.

diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 5401b7a6fe..fb514ba693 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
         {



Summary of changes:
 libgnucash/engine/Account.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)



More information about the gnucash-changes mailing list