From b30690664fc961febb817c9c8a7731a7ed4ff762 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Tue, 13 May 2025 09:50:27 -0400 Subject: [PATCH] commit: clear group membership from abandoned commit item copies --- common/commit.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/commit.cpp b/common/commit.cpp index 56ac03e297..e0f01bd6b4 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include COMMIT::COMMIT() @@ -40,7 +41,21 @@ COMMIT::~COMMIT() for( COMMIT_LINE& ent : m_changes ) { if( ent.m_copy ) + { + // If we're deleting changes, we have a commit that is being abandoned, + // and the copies of items with group memberships can have their group membership + // cleared as long as we make sure that group doesn't hold a reference to the copy. + if( ent.m_copy->GetParentGroup() ) + { + // This is a copy, so it should not be in the group. + // (RemoveItem() returns false when it doesn't find the item), + // but if it is we need to remove it to prevent a crash. + wxASSERT( ent.m_copy->GetParentGroup()->RemoveItem( ent.m_copy ) == false ); + ent.m_copy->SetParentGroup( nullptr ); + } + delete ent.m_copy; + } } }