leaks: Handle subclasses in filters even for unhandled/lazy loaded types
authorThibault Saunier <thibault.saunier@osg.samsung.com>
Sat, 20 May 2017 11:24:18 +0000 (13:24 +0200)
committerThibault Saunier <thibault.saunier@osg.samsung.com>
Sat, 20 May 2017 13:42:16 +0000 (15:42 +0200)
Using typename in the set of unhandled types instead of the quark so
that we also handle subclasses as with other filters.

plugins/tracers/gstleaks.c
plugins/tracers/gstleaks.h

index 5960c91a510d925c96332c79ac14e043c661a7c9..04a8abb6f29e049c2f2aaf94c72a589e19b348af 100644 (file)
@@ -139,10 +139,10 @@ set_filters (GstLeaksTracer * self, const gchar * filters)
        * should_handle_object_type() when/if the object type is actually
        * used. */
       if (!self->unhandled_filter)
-        self->unhandled_filter = g_hash_table_new (NULL, NULL);
+        self->unhandled_filter = g_hash_table_new_full (g_str_hash, g_str_equal,
+            g_free, NULL);
 
-      g_hash_table_add (self->unhandled_filter,
-          GUINT_TO_POINTER (g_quark_from_string (tmp[i])));
+      g_hash_table_add (self->unhandled_filter, g_strdup (tmp[i]));
       g_atomic_int_inc (&self->unhandled_filter_count);
       continue;
     }
@@ -193,6 +193,23 @@ set_stacktrace:
     gst_structure_free (params_struct);
 }
 
+static gboolean
+_expand_unhandled_filters (gchar * typename, gpointer unused_value,
+    GstLeaksTracer * self)
+{
+  GType type;
+
+  type = g_type_from_name (typename);
+
+  if (type == 0)
+    return FALSE;
+
+  g_atomic_int_dec_and_test (&self->unhandled_filter_count);
+  g_array_append_val (self->filter, type);
+
+  return TRUE;
+}
+
 static gboolean
 should_handle_object_type (GstLeaksTracer * self, GType object_type)
 {
@@ -202,23 +219,14 @@ should_handle_object_type (GstLeaksTracer * self, GType object_type)
     /* No filtering, handle all types */
     return TRUE;
 
-  if (g_atomic_int_get (&self->unhandled_filter_count)) {
-    GST_OBJECT_LOCK (self);
-    if (self->unhandled_filter) {
-      GQuark q;
-
-      q = g_type_qname (object_type);
-      if (g_hash_table_contains (self->unhandled_filter, GUINT_TO_POINTER (q))) {
-        g_array_append_val (self->filter, object_type);
-        g_hash_table_remove (self->unhandled_filter, GUINT_TO_POINTER (q));
+  if (object_type == 0)
+    return FALSE;
 
-        if (g_atomic_int_dec_and_test (&self->unhandled_filter_count))
-          g_clear_pointer (&self->unhandled_filter, g_hash_table_unref);
 
-        GST_OBJECT_UNLOCK (self);
-        return TRUE;
-      }
-    }
+  if (g_atomic_int_get (&self->unhandled_filter_count)) {
+    GST_OBJECT_LOCK (self);
+    g_hash_table_foreach_remove (self->unhandled_filter,
+        (GHRFunc) _expand_unhandled_filters, self);
     GST_OBJECT_UNLOCK (self);
   }
 
index 339bae89c5376595128b69417fa0f6c7d3e09d4a..71277b8cf418beaf3235957f4b04a77251620806 100644 (file)
@@ -60,7 +60,7 @@ struct _GstLeaksTracer {
   GHashTable *added;
   /* Set of owned ObjectLog.  Protected by object lock */
   GHashTable *removed;
-  /* If not NULL, contain a set of GQuark representing type filter not
+  /* If not NULL, contain a set of string representing type filter not
    * (yet?) known by the type system.
    * Protected by object lock. */
   GHashTable *unhandled_filter;