From 079ef4daf6269ed9b28270a681f3eff368f482c6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 24 Oct 2016 16:32:18 +0200 Subject: [PATCH] fix several memory leaks: SketchObject::delGeometry SketchObject::delExternal SketchObject::delAllExternal SketchObject::validateExternalLinks --- .../Sketcher/App/PropertyConstraintList.cpp | 2 ++ src/Mod/Sketcher/App/SketchObject.cpp | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Mod/Sketcher/App/PropertyConstraintList.cpp b/src/Mod/Sketcher/App/PropertyConstraintList.cpp index d0943c4f55..e43c3b555c 100644 --- a/src/Mod/Sketcher/App/PropertyConstraintList.cpp +++ b/src/Mod/Sketcher/App/PropertyConstraintList.cpp @@ -302,6 +302,8 @@ void PropertyConstraintList::Restore(Base::XMLReader &reader) // assignment setValues(values); + for (Constraint* it : values) + delete it; } Property *PropertyConstraintList::Copy(void) const diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index a9ea401331..00ac6bb153 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -655,6 +655,8 @@ int SketchObject::delGeometry(int GeoId) this->Geometry.setValues(newVals); this->Constraints.setValues(newConstraints); + for (Constraint* it : newConstraints) + delete it; this->Constraints.acceptGeometry(getCompleteGeometry()); rebuildVertexIndex(); @@ -2882,11 +2884,15 @@ int SketchObject::delExternal(int ExtGeoId) Base::Console().Error("%s\n", e.what()); // revert to original values ExternalGeometry.setValues(originalObjects,originalSubElements); + for (Constraint* it : newConstraints) + delete it; return -1; } solverNeedsUpdate=true; Constraints.setValues(newConstraints); + for (Constraint* it : newConstraints) + delete it; Constraints.acceptGeometry(getCompleteGeometry()); rebuildVertexIndex(); return 0; @@ -2917,7 +2923,7 @@ int SketchObject::delAllExternal() newConstraints.push_back(copiedConstr); } } - + ExternalGeometry.setValues(Objects,SubElements); try { rebuildExternalGeometry(); @@ -2926,11 +2932,15 @@ int SketchObject::delAllExternal() Base::Console().Error("%s\n", e.what()); // revert to original values ExternalGeometry.setValues(originalObjects,originalSubElements); + for (Constraint* it : newConstraints) + delete it; return -1; } solverNeedsUpdate=true; Constraints.setValues(newConstraints); + for (Constraint* it : newConstraints) + delete it; Constraints.acceptGeometry(getCompleteGeometry()); rebuildVertexIndex(); return 0; @@ -3037,13 +3047,13 @@ void SketchObject::validateExternalLinks(void) { std::vector Objects = ExternalGeometry.getValues(); std::vector SubElements = ExternalGeometry.getSubValues(); - - bool rebuild = false ; + + bool rebuild = false; for (int i=0; i < int(Objects.size()); i++) { const App::DocumentObject *Obj=Objects[i]; const std::string SubElement=SubElements[i]; - + const Part::Feature *refObj=static_cast(Obj); const Part::TopoShape& refShape=refObj->Shape.getShape(); @@ -3055,7 +3065,7 @@ void SketchObject::validateExternalLinks(void) rebuild = true ; Objects.erase(Objects.begin()+i); SubElements.erase(SubElements.begin()+i); - + const std::vector< Constraint * > &constraints = Constraints.getValues(); std::vector< Constraint * > newConstraints(0); int GeoId = GeoEnum::RefExt - i; @@ -3076,8 +3086,10 @@ void SketchObject::validateExternalLinks(void) newConstraints.push_back(copiedConstr); } } - + Constraints.setValues(newConstraints); + for (Constraint* it : newConstraints) + delete it; i--; // we deleted an item, so the next one took its place } }