From 6ebee86867fb5ff110445793b1243655a46b7a55 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 30 Oct 2020 13:21:51 +0100 Subject: [PATCH] Sketcher: [skip ci] avoid possible memory leak --- src/Mod/Sketcher/App/SketchObject.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 493fad8c6d..0ecd466bae 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -5278,7 +5278,7 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m if( knotIndex > bsp->countKnots() || knotIndex < 1 ) // knotindex in OCC 1 -> countKnots THROWMT(Base::ValueError,QT_TRANSLATE_NOOP("Exceptions", "The knot index is out of bounds. Note that in accordance with OCC notation, the first knot has index 1 and not zero.")) - Part::GeomBSplineCurve *bspline = nullptr; + std::unique_ptr bspline; int curmult = bsp->getMultiplicity(knotIndex); @@ -5289,8 +5289,7 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m THROWMT(Base::ValueError,QT_TRANSLATE_NOOP("Exceptions", "The multiplicity cannot be decreased beyond zero.")) try { - - bspline = static_cast(bsp->clone()); + bspline.reset(static_cast(bsp->clone())); if(multiplicityincr > 0) { // increase multiplicity bspline->increaseMultiplicity(knotIndex, curmult + multiplicityincr); @@ -5303,7 +5302,6 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m } } catch (const Base::Exception& e) { - delete bspline; Base::Console().Error("%s\n", e.what()); return false; } @@ -5394,9 +5392,8 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m // deep copy for(size_t i=0; iclone();