From dc5a62f70234f729c0f3443ab725e9f0232cc1fe Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Tue, 16 Apr 2019 13:29:00 +0200 Subject: [PATCH] gstinfo: clean up function pointer names hashtable 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 | 1 + gst/gst_private.h | 1 + gst/gstinfo.c | 30 ++++++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/gst/gst.c b/gst/gst.c index f68beee..2f4c789 100644 --- 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 ())); diff --git a/gst/gst_private.h b/gst/gst_private.h index 0edc93c..b4567d6 100644 --- a/gst/gst_private.h +++ b/gst/gst_private.h @@ -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); diff --git a/gst/gstinfo.c b/gst/gstinfo.c index f3ae152..c2256db 100644 --- a/gst/gstinfo.c +++ b/gst/gstinfo.c @@ -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, ...) -- 2.7.4