info: Deprecate gst_debug_category_free()
authorSebastian Dröge <sebastian@centricular.com>
Sun, 14 Jul 2019 18:36:00 +0000 (21:36 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Mon, 15 Jul 2019 08:35:07 +0000 (11:35 +0300)
And change it to do nothing at all.

As debug categories don't use reference counting and they can be
retrieved from anywhere at any time by name, it is fundamentally unsafe
to free them at any point in time except for right before the end of the
process.

No code apart from a unit test seems to be currently using the function,
so deprecate it and also change it to do nothing at all.

gst/gstinfo.c
gst/gstinfo.h
tests/check/gst/gstinfo.c

index 45f9fa1..16582e0 100644 (file)
@@ -1742,27 +1742,20 @@ _gst_debug_category_new (const gchar * name, guint color,
   return cat;
 }
 
+#ifndef GST_REMOVE_DEPRECATED
 /**
  * gst_debug_category_free:
  * @category: #GstDebugCategory to free.
  *
  * Removes and frees the category and all associated resources.
+ *
+ * Deprecated: This function can easily cause memory corruption, don't use it.
  */
 void
 gst_debug_category_free (GstDebugCategory * category)
 {
-  if (category == NULL)
-    return;
-
-  /* remove from category list */
-  g_mutex_lock (&__cat_mutex);
-  __categories = g_slist_remove (__categories, category);
-  g_mutex_unlock (&__cat_mutex);
-
-  g_free ((gpointer) category->name);
-  g_free ((gpointer) category->description);
-  g_slice_free (GstDebugCategory, category);
 }
+#endif
 
 /**
  * gst_debug_category_set_threshold:
@@ -2304,10 +2297,12 @@ gst_debug_unset_threshold_for_name (const gchar * name)
 {
 }
 
+#ifndef GST_REMOVE_DEPRECATED
 void
 gst_debug_category_free (GstDebugCategory * category)
 {
 }
+#endif
 
 void
 gst_debug_category_set_threshold (GstDebugCategory * category,
index 257564a..74d7406 100644 (file)
@@ -446,8 +446,7 @@ void            gst_debug_set_threshold_from_string  (const gchar * list, gboole
 GST_API
 void            gst_debug_unset_threshold_for_name   (const gchar * name);
 
-
-GST_API
+GST_DEPRECATED
 void            gst_debug_category_free              (GstDebugCategory *       category);
 
 GST_API
@@ -1492,7 +1491,9 @@ GST_TRACE (const char *format, ...)
 
 #define GST_DEBUG_CATEGORY_INIT(var,name,color,desc)   G_STMT_START{ }G_STMT_END
 #define GST_DEBUG_CATEGORY_GET(var,name)               G_STMT_START{ }G_STMT_END
+#ifndef GST_DISABLE_DEPRECATED
 #define gst_debug_category_free(category)              G_STMT_START{ }G_STMT_END
+#endif
 #define gst_debug_category_set_threshold(category,level) G_STMT_START{ }G_STMT_END
 #define gst_debug_category_reset_threshold(category)   G_STMT_START{ }G_STMT_END
 #define gst_debug_category_get_threshold(category)     (GST_LEVEL_NONE)
index 41d5cc5..b31c962 100644 (file)
@@ -480,9 +480,6 @@ GST_START_TEST (info_post_gst_init_category_registration)
     fail_unless_equals_int (gst_debug_category_get_threshold (cats[0xb10]),
         GST_LEVEL_LOG);
   }
-
-  for (i = 0; i < G_N_ELEMENTS (cats); ++i)
-    gst_debug_category_free (cats[i]);
 }
 
 GST_END_TEST;