From c242b5de5b60a0a02bc2142513db0768498083d2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 12 May 2023 10:43:29 +0200 Subject: [PATCH] Path: fixes #9403: Memory leak in Path --- src/Mod/Path/PathSimulator/App/PathSim.cpp | 10 ++-------- src/Mod/Path/PathSimulator/App/PathSim.h | 5 +++-- src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Mod/Path/PathSimulator/App/PathSim.cpp b/src/Mod/Path/PathSimulator/App/PathSim.cpp index ee9b5b9931..10ef7fc88a 100644 --- a/src/Mod/Path/PathSimulator/App/PathSim.cpp +++ b/src/Mod/Path/PathSimulator/App/PathSim.cpp @@ -32,27 +32,21 @@ TYPESYSTEM_SOURCE(PathSimulator::PathSim , Base::BaseClass); PathSim::PathSim() { - m_stock = nullptr; - m_tool = nullptr; } PathSim::~PathSim() { - if (m_stock) - delete m_stock; - if (m_tool) - delete m_tool; } void PathSim::BeginSimulation(Part::TopoShape * stock, float resolution) { Base::BoundBox3d bbox = stock->getBoundBox(); - m_stock = new cStock(bbox.MinX, bbox.MinY, bbox.MinZ, bbox.LengthX(), bbox.LengthY(), bbox.LengthZ(), resolution); + m_stock = std::make_unique(bbox.MinX, bbox.MinY, bbox.MinZ, bbox.LengthX(), bbox.LengthY(), bbox.LengthZ(), resolution); } void PathSim::SetToolShape(const TopoDS_Shape& toolShape, float resolution) { - m_tool = new cSimTool(toolShape, resolution); + m_tool = std::make_unique(toolShape, resolution); } Base::Placement * PathSim::ApplyCommand(Base::Placement * pos, Command * cmd) diff --git a/src/Mod/Path/PathSimulator/App/PathSim.h b/src/Mod/Path/PathSimulator/App/PathSim.h index c6bf74f19e..2b09a0b45f 100644 --- a/src/Mod/Path/PathSimulator/App/PathSim.h +++ b/src/Mod/Path/PathSimulator/App/PathSim.h @@ -23,6 +23,7 @@ #ifndef PATHSIMULATOR_PathSim_H #define PATHSIMULATOR_PathSim_H +#include #include #include @@ -51,8 +52,8 @@ namespace PathSimulator Base::Placement * ApplyCommand(Base::Placement * pos, Command * cmd); public: - cStock * m_stock; - cSimTool *m_tool; + std::unique_ptr m_stock; + std::unique_ptr m_tool; }; } //namespace Path diff --git a/src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp b/src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp index 6097889989..7c96a661cb 100644 --- a/src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp +++ b/src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp @@ -86,7 +86,7 @@ PyObject* PathSimPy::GetResultMesh(PyObject * args) { if (!PyArg_ParseTuple(args, "")) return nullptr; - cStock *stock = getPathSimPtr()->m_stock; + cStock *stock = getPathSimPtr()->m_stock.get(); if (!stock) { PyErr_SetString(PyExc_RuntimeError, "Simulation has stock object");