[glib/wip/gcleanup: 31/78] gmodule: Cleanup main_module, ie: self



commit 66510c642da47a16a51e1853859186e9db15bc9f
Author: Stef Walter <stefw gnome org>
Date:   Sun Nov 10 11:16:14 2013 +0100

    gmodule: Cleanup main_module, ie: self
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711767

 build/glib-test.supp |   11 +++++++++++
 gmodule/Makefile.am  |    1 +
 gmodule/gmodule.c    |    9 +++++++++
 3 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/build/glib-test.supp b/build/glib-test.supp
index 90ab4df..dec4201 100644
--- a/build/glib-test.supp
+++ b/build/glib-test.supp
@@ -14,3 +14,14 @@
    fun:pthread_exit
    ...
 }
+
+{
+   dlopen-leaks-self
+   Memcheck:Leak
+   fun:calloc
+   fun:_dlerror_run
+   fun:dlopen@@*
+   fun:_g_module_self
+   fun:g_module_open
+   ...
+}
diff --git a/gmodule/Makefile.am b/gmodule/Makefile.am
index 6acd846..a033084 100644
--- a/gmodule/Makefile.am
+++ b/gmodule/Makefile.am
@@ -4,6 +4,7 @@ include $(top_srcdir)/glib.mk
 AM_CPPFLAGS =                          \
        $(glib_INCLUDES)                \
        -DG_LOG_DOMAIN=\"GModule\"      \
+       -DG_CLEANUP_SCOPE=gmodule_cleanup \
        @GLIB_DEBUG_FLAGS@              \
        -DG_DISABLE_DEPRECATED
 
diff --git a/gmodule/gmodule.c b/gmodule/gmodule.c
index ebeacef..491c94b 100644
--- a/gmodule/gmodule.c
+++ b/gmodule/gmodule.c
@@ -193,6 +193,7 @@
  * faster access and because it has special semantics.
  */
 
+G_CLEANUP_DEFINE;
 
 /* --- structures --- */
 struct _GModule
@@ -473,6 +474,13 @@ _g_module_debug_init (void)
 
 static GRecMutex g_module_global_lock;
 
+static void
+cleanup_main_module (void)
+{
+  _g_module_close (main_module->handle, FALSE);
+  g_free (main_module);
+}
+
 GModule*
 g_module_open (const gchar    *file_name,
               GModuleFlags    flags)
@@ -508,6 +516,7 @@ g_module_open (const gchar    *file_name,
              main_module->is_resident = TRUE;
              main_module->unload = NULL;
              main_module->next = NULL;
+             G_CLEANUP_FUNC_IN_PHASE (cleanup_main_module, G_CLEANUP_PHASE_LATE);
            }
        }
       else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]