info: Properly start and end dwfl sessions when getting stack traces
[platform/upstream/gstreamer.git] / gst / gstallocator.c
index 6363ba5..367fc2a 100644 (file)
@@ -210,6 +210,8 @@ gst_allocator_register (const gchar * name, GstAllocator * allocator)
       allocator, name);
 
   g_rw_lock_writer_lock (&lock);
+  /* The ref will never be released */
+  GST_OBJECT_FLAG_SET (allocator, GST_OBJECT_FLAG_MAY_BE_LEAKED);
   g_hash_table_insert (allocators, (gpointer) name, (gpointer) allocator);
   g_rw_lock_writer_unlock (&lock);
 }
@@ -221,8 +223,9 @@ gst_allocator_register (const gchar * name, GstAllocator * allocator)
  * Find a previously registered allocator with @name. When @name is %NULL, the
  * default allocator will be returned.
  *
- * Returns: (transfer full): a #GstAllocator or %NULL when the allocator with @name was not
- * registered. Use gst_object_unref() to release the allocator after usage.
+ * Returns: (transfer full) (nullable): a #GstAllocator or %NULL when
+ * the allocator with @name was not registered. Use gst_object_unref()
+ * to release the allocator after usage.
  */
 GstAllocator *
 gst_allocator_find (const gchar * name)
@@ -535,7 +538,11 @@ default_free (GstAllocator * allocator, GstMemory * mem)
 static void
 gst_allocator_sysmem_finalize (GObject * obj)
 {
-  g_warning ("The default memory allocator was freed!");
+  /* Don't raise warnings if we are shutting down */
+  if (_default_allocator)
+    g_warning ("The default memory allocator was freed!");
+
+  ((GObjectClass *) gst_allocator_sysmem_parent_class)->finalize (obj);
 }
 
 static void
@@ -569,10 +576,11 @@ gst_allocator_sysmem_init (GstAllocatorSysmem * allocator)
 }
 
 void
-_priv_gst_memory_initialize (void)
+_priv_gst_allocator_initialize (void)
 {
   g_rw_lock_init (&lock);
-  allocators = g_hash_table_new (g_str_hash, g_str_equal);
+  allocators = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
+      gst_object_unref);
 
 #ifdef HAVE_GETPAGESIZE
 #ifdef MEMORY_ALIGNMENT_PAGESIZE
@@ -591,6 +599,18 @@ _priv_gst_memory_initialize (void)
   _default_allocator = gst_object_ref (_sysmem_allocator);
 }
 
+void
+_priv_gst_allocator_cleanup (void)
+{
+  gst_object_unref (_sysmem_allocator);
+  _sysmem_allocator = NULL;
+
+  gst_object_unref (_default_allocator);
+  _default_allocator = NULL;
+
+  g_clear_pointer (&allocators, g_hash_table_unref);
+}
+
 /**
  * gst_memory_new_wrapped:
  * @flags: #GstMemoryFlags