Re: patch to remove false memory leak detection

Michael Reinhardt <[email protected]> Thu, 21 Jan 2016 17:18:31 +0100
Newsgroups gmane.comp.video.openexr.devel
Message-ID <[email protected]>
Hi,

I submitted the patch Nov 5 2013 ("[Openexr-devel] Memory leaks in 
2.01"). It is also attached. The full thread was started Nov 4 2013 by 
Gerhard Huber.
There are some answers to my mail that you should read concerning the 
drawbacks of this approach.

Best regards,
Michael

Am 21.01.2016 um 16:35 schrieb Reid, Darren (NBCC Miramichi):
>
> I am searching for a patch that Michael Reinhardt created that added a 
> staticUninitialize() function to delete the typemap and thus stop 
> memory leak tools from reporting a bogus leak. Can anyone point me to 
> it? Thanks!
>
> -Darren
>
>
>
> _______________________________________________
> Openexr-devel mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/openexr-devel

-- 

Research Associate
Immersive Media & Communication Group
Vision & Imaging Technologies Department
[email protected]

Tel +49 30 31002‐441

Fraunhofer Heinrich Hertz Institute
Einsteinufer 37, 10587 Berlin, Germany
www.hhi.fraunhofer.de

_______________________________________________
Openexr-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/openexr-devel
Uninit.patch (text/plain, 2.7 KB)
Index: include/OpenEXR/ImfAttribute.h
===================================================================
--- include/OpenEXR/ImfAttribute.h	(revision 169)
+++ include/OpenEXR/ImfAttribute.h	(working copy)
@@ -106,7 +106,12 @@
 
     static bool            knownType (const char typeName[]);
 
+    //------------------------------------------------------
+    // Un-register all known attributes.
+    //------------------------------------------------------
 
+    static void clearAttributeRegistration();
+
   protected:
 
     //--------------------------------------------------
Index: include/OpenEXR/ImfHeader.h
===================================================================
--- include/OpenEXR/ImfHeader.h	(revision 169)
+++ include/OpenEXR/ImfHeader.h	(working copy)
@@ -493,6 +493,7 @@
 //------------------------------------------------------------------------
 
 void staticInitialize ();
+void staticUninitialize ();
 
 
 //-----------------
Index: src/lib/IlmImf/ImfAttribute.cpp
===================================================================
--- src/lib/IlmImf/ImfAttribute.cpp	(revision 169)
+++ src/lib/IlmImf/ImfAttribute.cpp	(working copy)
@@ -83,22 +83,32 @@
     Mutex mutex;
 };
 
+static Mutex criticalSection;
+static LockedTypeMap* typeMapVar = 0;
 
 LockedTypeMap &
 typeMap ()
 {
-    static Mutex criticalSection;
     Lock lock (criticalSection);
 
-    static LockedTypeMap* typeMap = 0;
+    if (typeMapVar == 0)
+    typeMapVar = new LockedTypeMap ();
 
-    if (typeMap == 0)
-    typeMap = new LockedTypeMap ();
+    return *typeMapVar;
+}
 
-    return *typeMap;
+void
+clearTypeMap ()
+{
+    Lock lock (criticalSection);
+
+    if (typeMapVar != 0)
+    {
+        delete typeMapVar;
+        typeMapVar = 0;
+    }
 }
 
-
 } // namespace
 
 
@@ -137,7 +147,16 @@
     tMap.erase (typeName);
 }
 
+void
+  Attribute::clearAttributeRegistration ()
+{
+    LockedTypeMap& tMap = typeMap();
+    Lock lock (tMap.mutex);
 
+    tMap.clear ();
+    clearTypeMap();
+}
+
 Attribute *
 Attribute::newAttribute (const char typeName[])
 {
Index: src/lib/IlmImf/ImfHeader.cpp
===================================================================
--- src/lib/IlmImf/ImfHeader.cpp	(revision 169)
+++ src/lib/IlmImf/ImfHeader.cpp	(working copy)
@@ -1229,15 +1229,14 @@
     }
 }
 
+static bool initialized = false;
+static Mutex criticalSection;
 
 void
 staticInitialize ()
 {
-    static Mutex criticalSection;
     Lock lock (criticalSection);
 
-    static bool initialized = false;
-
     if (!initialized)
     {
       //
@@ -1277,5 +1276,14 @@
     }
 }
 
+void
+staticUninitialize ()
+{
+    Lock lock (criticalSection);
 
+    Attribute::clearAttributeRegistration();
+
+    initialized = false;
+}
+
 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT