From 1e5c5f4e7f77f08d5ea0d234a749b5815d5b99ac Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 27 Apr 2021 13:02:57 +0200 Subject: [PATCH] Path: [skip ci] fix memory leaks --- src/Mod/Path/App/AreaPyImp.cpp | 8 ++++++-- src/Mod/Path/App/VoronoiEdgePyImp.cpp | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Mod/Path/App/AreaPyImp.cpp b/src/Mod/Path/App/AreaPyImp.cpp index 959f1f8a8b..a02642a71e 100644 --- a/src/Mod/Path/App/AreaPyImp.cpp +++ b/src/Mod/Path/App/AreaPyImp.cpp @@ -206,8 +206,12 @@ PyObject *AreaPy::PyMake(struct _typeobject *, PyObject *args, PyObject *kwd) / AreaPy* ret = new AreaPy(new Area); if(!ret->setParams(args,kwd)) { Py_DecRef(ret); - return 0; + return nullptr; } + + // If setParams() was successful it increments the ref counter. + // So, it must be decremented again. + Py_DecRef(ret); return ret; } @@ -402,7 +406,7 @@ PyObject* AreaPy::setParams(PyObject *args, PyObject *keywds) if (!PyArg_ParseTupleAndKeywords(args, keywds, "|" PARAM_PY_KWDS(AREA_PARAMS_CONF), kwlist, PARAM_REF(PARAM_FNAME,AREA_PARAMS_CONF))) - return 0; + return nullptr; PY_TRY { //populate 'params' with the CONF variables diff --git a/src/Mod/Path/App/VoronoiEdgePyImp.cpp b/src/Mod/Path/App/VoronoiEdgePyImp.cpp index 158616b8a2..52537a58a6 100644 --- a/src/Mod/Path/App/VoronoiEdgePyImp.cpp +++ b/src/Mod/Path/App/VoronoiEdgePyImp.cpp @@ -412,9 +412,9 @@ PyObject* VoronoiEdgePy::toShape(PyObject *args) auto v0 = e->ptr->vertex0(); auto v1 = e->ptr->vertex1(); if (v0 && v1) { - auto p = new Part::GeomLineSegment; - p->setPoints(e->dia->scaledVector(*v0, z0), e->dia->scaledVector(*v1, z1)); - Handle(Geom_Curve) h = Handle(Geom_Curve)::DownCast(p->handle()); + Part::GeomLineSegment p; + p.setPoints(e->dia->scaledVector(*v0, z0), e->dia->scaledVector(*v1, z1)); + Handle(Geom_Curve) h = Handle(Geom_Curve)::DownCast(p.handle()); BRepBuilderAPI_MakeEdge mkBuilder(h, h->FirstParameter(), h->LastParameter()); return new Part::TopoShapeEdgePy(new Part::TopoShape(mkBuilder.Shape())); } @@ -461,9 +461,9 @@ PyObject* VoronoiEdgePy::toShape(PyObject *args) end.x(origin.x() + direction.x() * k); end.y(origin.y() + direction.y() * k); } - auto p = new Part::GeomLineSegment; - p->setPoints(e->dia->scaledVector(begin, z0), e->dia->scaledVector(end, z1)); - Handle(Geom_Curve) h = Handle(Geom_Curve)::DownCast(p->handle()); + Part::GeomLineSegment p; + p.setPoints(e->dia->scaledVector(begin, z0), e->dia->scaledVector(end, z1)); + Handle(Geom_Curve) h = Handle(Geom_Curve)::DownCast(p.handle()); BRepBuilderAPI_MakeEdge mkBuilder(h, h->FirstParameter(), h->LastParameter()); return new Part::TopoShapeEdgePy(new Part::TopoShape(mkBuilder.Shape())); } @@ -574,12 +574,12 @@ PyObject* VoronoiEdgePy::toShape(PyObject *args) gp_Ax2 pb(pbLocn, pbNorm, pbXdir); Handle(Geom_Parabola) parabola = new Geom_Parabola(pb, focal); - auto arc = new Part::GeomArcOfParabola; - arc->setHandle(parabola); - arc->setRange(dist0, dist1, false); + Part::GeomArcOfParabola arc; + arc.setHandle(parabola); + arc.setRange(dist0, dist1, false); // get a shape for the parabola arc - Handle(Geom_Curve) h = Handle(Geom_Curve)::DownCast(arc->handle()); + Handle(Geom_Curve) h = Handle(Geom_Curve)::DownCast(arc.handle()); BRepBuilderAPI_MakeEdge mkBuilder(h, h->FirstParameter(), h->LastParameter()); return new Part::TopoShapeEdgePy(new Part::TopoShape(mkBuilder.Shape())); }