From 14ec1e660387796de99110073ae5ab4057d4cc13 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 14 Jul 2024 12:02:21 +0200 Subject: [PATCH] Measure: Fix memory leak in MeasureDistanceInfo Fixes #15349 --- src/Mod/Measure/App/MeasureDistance.cpp | 3 +-- src/Mod/Part/App/MeasureClient.cpp | 3 +-- src/Mod/Part/App/MeasureInfo.h | 9 ++++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Mod/Measure/App/MeasureDistance.cpp b/src/Mod/Measure/App/MeasureDistance.cpp index 20cba5b011..59bbdc15ae 100644 --- a/src/Mod/Measure/App/MeasureDistance.cpp +++ b/src/Mod/Measure/App/MeasureDistance.cpp @@ -150,7 +150,6 @@ bool MeasureDistance::getShape(App::PropertyLinkSub* prop, TopoDS_Shape& rShape) } auto handler = getGeometryHandler(mod); - std::string obName = static_cast(ob->getNameInDocument()); App::SubObjectT subject{ob, subName.c_str()}; auto info = handler(subject); if (!info->valid) { @@ -158,7 +157,7 @@ bool MeasureDistance::getShape(App::PropertyLinkSub* prop, TopoDS_Shape& rShape) } auto distanceInfo = std::dynamic_pointer_cast(info); - rShape = *distanceInfo->getShape(); + rShape = distanceInfo->getShape(); return true; } diff --git a/src/Mod/Part/App/MeasureClient.cpp b/src/Mod/Part/App/MeasureClient.cpp index 5621a88691..283b5dcef7 100644 --- a/src/Mod/Part/App/MeasureClient.cpp +++ b/src/Mod/Part/App/MeasureClient.cpp @@ -410,8 +410,7 @@ MeasureDistanceInfoPtr MeasureDistanceHandler(const App::SubObjectT& subject) // return a persistent copy of the TopoDS_Shape here as shape will go out of scope at end BRepBuilderAPI_Copy copy(shape); - const TopoDS_Shape* newShape = new TopoDS_Shape(copy.Shape()); - return std::make_shared(true, newShape); + return std::make_shared(true, copy.Shape()); } diff --git a/src/Mod/Part/App/MeasureInfo.h b/src/Mod/Part/App/MeasureInfo.h index 6af72a962e..678dd9e1d5 100644 --- a/src/Mod/Part/App/MeasureInfo.h +++ b/src/Mod/Part/App/MeasureInfo.h @@ -37,8 +37,7 @@ #include #include #include - -class TopoDS_Shape; +#include namespace Part { @@ -93,14 +92,14 @@ public: class PartExport MeasureDistanceInfo : public MeasureInfo { public: MeasureDistanceInfo() = default; - explicit MeasureDistanceInfo(bool val, const TopoDS_Shape* shp) : + explicit MeasureDistanceInfo(bool val, const TopoDS_Shape& shp) : MeasureInfo(val), shape(shp) {} ~MeasureDistanceInfo() override = default; - const TopoDS_Shape* getShape() { return shape; } + const TopoDS_Shape& getShape() { return shape; } private: - const TopoDS_Shape* shape{nullptr}; + TopoDS_Shape shape; }; class PartExport MeasureLengthInfo : public MeasureInfo {