gstinfo: clean up function pointer names hashtable
authorMathieu Duponchelle <mathieu@centricular.com>
Tue, 16 Apr 2019 11:29:00 +0000 (13:29 +0200)
committerMathieu Duponchelle <mathieu@centricular.com>
Wed, 17 Apr 2019 21:03:56 +0000 (23:03 +0200)
And add strduped function pointer names to the global quark
table, so that they don't get reported as lost by valgrind.

This allows us to use GST_DEBUG when running tests under
valgrind.

gst/gst.c
gst/gst_private.h
gst/gstinfo.c

index f68beee..2f4c789 100644 (file)
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -1125,6 +1125,7 @@ gst_deinit (void)
 
   _priv_gst_caps_features_cleanup ();
   _priv_gst_caps_cleanup ();
+  _priv_gst_debug_cleanup ();
 
   g_type_class_unref (g_type_class_peek (gst_object_get_type ()));
   g_type_class_unref (g_type_class_peek (gst_pad_get_type ()));
index 0edc93c..b4567d6 100644 (file)
@@ -142,6 +142,7 @@ G_GNUC_INTERNAL  void  _priv_gst_date_time_initialize (void);
 G_GNUC_INTERNAL  void  _priv_gst_allocator_cleanup (void);
 G_GNUC_INTERNAL  void  _priv_gst_caps_features_cleanup (void);
 G_GNUC_INTERNAL  void  _priv_gst_caps_cleanup (void);
+G_GNUC_INTERNAL  void  _priv_gst_debug_cleanup (void);
 
 /* called from gst_task_cleanup_all(). */
 G_GNUC_INTERNAL  void  _priv_gst_element_cleanup (void);
index f3ae152..c2256db 100644 (file)
@@ -2060,7 +2060,7 @@ _gst_debug_nameof_funcptr (GstDebugFuncPtr func)
    * the name */
 #ifdef HAVE_DLADDR
   if (dladdr ((gpointer) func, &dl_info) && dl_info.dli_sname) {
-    gchar *name = g_strdup (dl_info.dli_sname);
+    const gchar *name = g_intern_string (dl_info.dli_sname);
 
     _gst_debug_register_funcptr (func, name);
     return name;
@@ -2068,9 +2068,12 @@ _gst_debug_nameof_funcptr (GstDebugFuncPtr func)
 #endif
   {
     gchar *name = g_strdup_printf ("%p", (gpointer) func);
+    const gchar *iname = g_intern_string (name);
 
-    _gst_debug_register_funcptr (func, name);
-    return name;
+    g_free (name);
+
+    _gst_debug_register_funcptr (func, iname);
+    return iname;
   }
 }
 
@@ -2083,8 +2086,22 @@ _gst_debug_register_funcptr (GstDebugFuncPtr func, const gchar * ptrname)
 
   if (!__gst_function_pointers)
     __gst_function_pointers = g_hash_table_new (g_direct_hash, g_direct_equal);
-  if (!g_hash_table_lookup (__gst_function_pointers, ptr))
+  if (!g_hash_table_lookup (__gst_function_pointers, ptr)) {
     g_hash_table_insert (__gst_function_pointers, ptr, (gpointer) ptrname);
+  }
+
+  g_mutex_unlock (&__dbg_functions_mutex);
+}
+
+void
+_priv_gst_debug_cleanup (void)
+{
+  g_mutex_lock (&__dbg_functions_mutex);
+
+  if (__gst_function_pointers) {
+    g_hash_table_unref (__gst_function_pointers);
+    __gst_function_pointers = NULL;
+  }
 
   g_mutex_unlock (&__dbg_functions_mutex);
 }
@@ -2168,6 +2185,11 @@ _gst_debug_nameof_funcptr (GstDebugFuncPtr func)
 }
 
 void
+_priv_gst_debug_cleanup (void)
+{
+}
+
+void
 gst_debug_log (GstDebugCategory * category, GstDebugLevel level,
     const gchar * file, const gchar * function, gint line,
     GObject * object, const gchar * format, ...)