From aee7dc0db829bf9b77cd7ef20f6c03e9d0f8c4a2 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 12 Nov 2015 19:30:30 +0300 Subject: [PATCH] gcc 4.9 compatibility: v2 (avoid memory leaks) --- src/GeomAPI/GeomAPI_Interface.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GeomAPI/GeomAPI_Interface.h b/src/GeomAPI/GeomAPI_Interface.h index de51617ae..27b822012 100644 --- a/src/GeomAPI/GeomAPI_Interface.h +++ b/src/GeomAPI/GeomAPI_Interface.h @@ -16,6 +16,11 @@ * \brief General base class for all interfaces in this package */ +template +void GeomAPI_deleter( void* p ) { + delete reinterpret_cast(p); +} + class GeomAPI_Interface { private: @@ -28,7 +33,7 @@ class GeomAPI_Interface /// Constructor by the impl pointer (used for internal needs) template explicit GeomAPI_Interface(T* theImpl) { - myImpl.reset(reinterpret_cast(theImpl)); + myImpl = std::shared_ptr(reinterpret_cast(theImpl), GeomAPI_deleter); } /// Destructor @@ -52,7 +57,7 @@ class GeomAPI_Interface /// Updates the impl (deletes the old one) template inline void setImpl(T* theImpl) { - myImpl.reset(reinterpret_cast(theImpl)); + myImpl = std::shared_ptr(reinterpret_cast(theImpl), GeomAPI_deleter); } /// Returns true if the impl is empty -- 2.30.2