Salome HOME
gcc 4.9 compatibility: v2 (avoid memory leaks) vsr/gcc_4_9_compat
authorvsr <vsr@opencascade.com>
Thu, 12 Nov 2015 16:30:30 +0000 (19:30 +0300)
committervsr <vsr@opencascade.com>
Thu, 12 Nov 2015 16:30:30 +0000 (19:30 +0300)
src/GeomAPI/GeomAPI_Interface.h

index de51617ae7e8b45b861e1f59d95db2fd72d21a7c..27b8220129d590ed378e3f818b0f6c8932446c18 100644 (file)
  * \brief General base class for all interfaces in this package
  */
 
+template <typename T>
+void GeomAPI_deleter( void* p ) {
+   delete reinterpret_cast<T*>(p);
+}
+
 class GeomAPI_Interface
 {
  private:
@@ -28,7 +33,7 @@ class GeomAPI_Interface
   /// Constructor by the impl pointer (used for internal needs)
   template<class T> explicit GeomAPI_Interface(T* theImpl)
   {
-    myImpl.reset(reinterpret_cast<char*>(theImpl));
+    myImpl = std::shared_ptr<char>(reinterpret_cast<char*>(theImpl), GeomAPI_deleter<T>);
   }
 
   /// Destructor
@@ -52,7 +57,7 @@ class GeomAPI_Interface
   /// Updates the impl (deletes the old one)
   template<class T> inline void setImpl(T* theImpl)
   {
-    myImpl.reset(reinterpret_cast<char*>(theImpl));
+    myImpl = std::shared_ptr<char>(reinterpret_cast<char*>(theImpl), GeomAPI_deleter<T>);
   }
 
   /// Returns true if the impl is empty