svx/source/svdraw/svdmodel.cxx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
New commits: commit 958854ac4c701e6b1444178514b1a6e4e03be94e Author: Mike Kaganski <[email protected]> AuthorDate: Thu Aug 19 13:46:21 2021 +0200 Commit: Mike Kaganski <[email protected]> CommitDate: Thu Aug 19 15:10:28 2021 +0200 Avoid infinite loop in dbgutil builds As mentioned in tdf#117162 comment 13, there are cases when SdrObject::Free does not modify maAllIncarnatedObjects. So the fix for tdf#143514 needs the change to account for that. Change-Id: I249c6a3b095c5d3c644dcb1bbc900b42793ea820 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120648 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> 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
