summaryrefslogtreecommitdiff
path: root/svx/source/svdraw/svdmodel.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'svx/source/svdraw/svdmodel.cxx')
-rw-r--r--svx/source/svdraw/svdmodel.cxx15
1 files changed, 9 insertions, 6 deletions
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index 7dcc8110faa4..a6f4aeed9ec0 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -197,13 +197,16 @@ SdrModel::~SdrModel()
if(!maAllIncarnatedObjects.empty())
{
SAL_WARN("svx","SdrModel::~SdrModel: Not all incarnations of SdrObjects deleted, possible memory leak (!)");
- // calling SdrObject::Free will change maAllIncarnatedObjects, and potentially remove more
- // than one - do not copy to another container, to not try to free already removed object.
- do
+ const std::vector<const SdrObject*> maRemainingObjects(maAllIncarnatedObjects.begin(),
+ maAllIncarnatedObjects.end());
+ for (auto pSdrObject : maRemainingObjects)
{
- SdrObject* pCandidate(const_cast<SdrObject*>(*maAllIncarnatedObjects.begin()));
- SdrObject::Free(pCandidate);
- } while (!maAllIncarnatedObjects.empty());
+ SdrObject* pCandidate(const_cast<SdrObject*>(pSdrObject));
+ // calling SdrObject::Free will change maAllIncarnatedObjects, and potentially remove
+ // more than one, so check if the candidate is still in the updated list before Free
+ if (maAllIncarnatedObjects.find(pSdrObject) != maAllIncarnatedObjects.end())
+ SdrObject::Free(pCandidate);
+ }
}
#endif