From 18ab387e584bb4100ccca3d78c57e578d71ddd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Deletrain?= Date: Tue, 17 Sep 2024 05:05:54 +0200 Subject: [PATCH] Fix spline data memory leak Fix memory leak with by use unique_ptr and make_unique --- src/twistSplineData.cpp | 11 ++++++----- src/twistSplineData.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/twistSplineData.cpp b/src/twistSplineData.cpp index 932cca0..8da10e0 100644 --- a/src/twistSplineData.cpp +++ b/src/twistSplineData.cpp @@ -32,8 +32,9 @@ void* TwistSplineData::creator(){ return new TwistSplineData; } -TwistSplineData::TwistSplineData() { - _twistSpline = new TwistSplineT(); +TwistSplineData::TwistSplineData() + : _twistSpline(std::make_unique()) +{ } TwistSplineData::~TwistSplineData() { @@ -43,7 +44,7 @@ void TwistSplineData::copy(const MPxData& other) { if (other.typeId() == TwistSplineData::id) { const TwistSplineData* otherData = (const TwistSplineData*) & other; const TwistSplineT * x = otherData->getSpline(); - _twistSpline = new TwistSplineT(*x); + _twistSpline = std::make_unique(*otherData->getSpline()); } else { // we need to convert to the other type based on its iff Tag @@ -53,11 +54,11 @@ void TwistSplineData::copy(const MPxData& other) { } const TwistSplineT* TwistSplineData::getSpline() const { - return _twistSpline; + return _twistSpline.get(); } TwistSplineT* TwistSplineData::getSpline() { - return _twistSpline; + return _twistSpline.get(); } MTypeId TwistSplineData::typeId() const { diff --git a/src/twistSplineData.h b/src/twistSplineData.h index 79a540d..2af1ae3 100644 --- a/src/twistSplineData.h +++ b/src/twistSplineData.h @@ -63,6 +63,6 @@ class TwistSplineData : public MPxData { static void* creator(); private: - TwistSplineT* _twistSpline; + std::unique_ptr _twistSpline; };