leaks: warn if object is destroyed while the tracer is disposing
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Fri, 8 Jul 2016 14:53:51 +0000 (16:53 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 8 Jul 2016 16:35:30 +0000 (17:35 +0100)
This should not happen and generally means some thread is still running.

https://bugzilla.gnome.org/show_bug.cgi?id=768578

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

index 3952f8e..7813ff8 100644 (file)
@@ -153,11 +153,19 @@ static void
 handle_object_destroyed (GstLeaksTracer * self, gpointer object)
 {
   GST_OBJECT_LOCK (self);
+  if (self->done) {
+    g_warning
+        ("object %p destroyed while the leaks tracer was finalizing. Some threads are still running?",
+        object);
+    goto out;
+  }
+
   g_hash_table_remove (self->objects, object);
 #ifdef G_OS_UNIX
   if (self->removed)
     g_hash_table_add (self->removed, object_log_new (object));
 #endif /* G_OS_UNIX */
+out:
   GST_OBJECT_UNLOCK (self);
 }
 
@@ -447,6 +455,8 @@ gst_leaks_tracer_finalize (GObject * object)
   GHashTableIter iter;
   gpointer obj;
 
+  self->done = TRUE;
+
   /* Tracers are destroyed as part of gst_deinit() so now is a good time to
    * report all the objects which are still alive. */
   leaks = log_leaked (self);
index 765634e..513ae95 100644 (file)
@@ -60,6 +60,7 @@ struct _GstLeaksTracer {
   GHashTable *added;
   /* Set of owned ObjectLog.  Protected by object lock */
   GHashTable *removed;
+  gboolean done;
 
   gboolean log_stack_trace;
 };