diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-08-19 13:46:21 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-08-19 15:10:28 +0200 |
commit | 958854ac4c701e6b1444178514b1a6e4e03be94e (patch) | |
tree | 4bd51dd1242ef39f764fc413b0fff9dd69f9a984 | |
parent | 9343551f5588ffa4916e2c5d33cbd6fcf56ca99d (diff) |
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 <mike.kaganski@collabora.com>
-rw-r--r-- | svx/source/svdraw/svdmodel.cxx | 15 |
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 |