The is_gst_mini_object_check would sometimes detect a proper GObject
as a mini object, and then bad things happen.
We know whether a pointer is a proper GObject or a MiniObject here
though, so just pass that information to the right code paths and
avoid the heuristics altogether.
Eliminates all remaining uses of object_is_gst_mini_object().
Fixes #1334
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2832>
typedef struct
{
gchar *creation_trace;
typedef struct
{
gchar *creation_trace;
GList *refing_infos;
} ObjectRefingInfos;
GList *refing_infos;
} ObjectRefingInfos;
const gchar *type_name;
} ObjectLog;
const gchar *type_name;
} ObjectLog;
-static inline gboolean
-object_is_gst_mini_object (gpointer obj)
-{
- return (G_TYPE_IS_DERIVED (GST_MINI_OBJECT_TYPE (obj)) &&
- G_TYPE_FUNDAMENTAL (GST_MINI_OBJECT_TYPE (obj)) == G_TYPE_BOXED);
-}
-
static ObjectLog *
object_log_new (gpointer obj, ObjectKind kind)
{
static ObjectLog *
object_log_new (gpointer obj, ObjectKind kind)
{
static void
handle_object_created (GstLeaksTracer * self, gpointer object, GType type,
static void
handle_object_created (GstLeaksTracer * self, gpointer object, GType type,
- ObjectKind kind = gobject ? GOBJECT : MINI_OBJECT; // FIXME: change arg to pass directly
ObjectRefingInfos *infos;
if (!should_handle_object_type (self, type))
return;
infos = g_malloc0 (sizeof (ObjectRefingInfos));
ObjectRefingInfos *infos;
if (!should_handle_object_type (self, type))
return;
infos = g_malloc0 (sizeof (ObjectRefingInfos));
- if (gobject)
- g_object_weak_ref ((GObject *) object, object_weak_cb, self);
- else
- gst_mini_object_weak_ref (GST_MINI_OBJECT_CAST (object),
- mini_object_weak_cb, self);
+ infos->kind = kind;
+ switch (kind) {
+ case GOBJECT:
+ g_object_weak_ref ((GObject *) object, object_weak_cb, self);
+ break;
+ case MINI_OBJECT:
+ gst_mini_object_weak_ref (GST_MINI_OBJECT_CAST (object),
+ mini_object_weak_cb, self);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
GST_OBJECT_LOCK (self);
if ((gint) self->trace_flags != -1)
GST_OBJECT_LOCK (self);
if ((gint) self->trace_flags != -1)
{
GstLeaksTracer *self = GST_LEAKS_TRACER_CAST (tracer);
{
GstLeaksTracer *self = GST_LEAKS_TRACER_CAST (tracer);
- handle_object_created (self, object, GST_MINI_OBJECT_TYPE (object), FALSE);
+ handle_object_created (self, object, GST_MINI_OBJECT_TYPE (object),
+ MINI_OBJECT);
if (g_type_is_a (object_type, GST_TYPE_TRACER))
return;
if (g_type_is_a (object_type, GST_TYPE_TRACER))
return;
- handle_object_created (self, object, object_type, TRUE);
+ handle_object_created (self, object, object_type, GOBJECT);
GType type;
guint ref_count;
GType type;
guint ref_count;
- if (object_is_gst_mini_object (obj)) {
- if (GST_MINI_OBJECT_FLAG_IS_SET (obj, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED))
- continue;
-
- type = GST_MINI_OBJECT_TYPE (obj);
- ref_count = ((GstMiniObject *) obj)->refcount;
- } else {
- if (GST_OBJECT_FLAG_IS_SET (obj, GST_OBJECT_FLAG_MAY_BE_LEAKED))
- continue;
-
- type = G_OBJECT_TYPE (obj);
- ref_count = ((GObject *) obj)->ref_count;
+ switch (((ObjectRefingInfos *) infos)->kind) {
+ case GOBJECT:
+ if (GST_OBJECT_FLAG_IS_SET (obj, GST_OBJECT_FLAG_MAY_BE_LEAKED))
+ continue;
+
+ type = G_OBJECT_TYPE (obj);
+ ref_count = ((GObject *) obj)->ref_count;
+ break;
+ case MINI_OBJECT:
+ if (GST_MINI_OBJECT_FLAG_IS_SET (obj,
+ GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED))
+ continue;
+
+ type = GST_MINI_OBJECT_TYPE (obj);
+ ref_count = ((GstMiniObject *) obj)->refcount;
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
}
l = g_list_prepend (l, leak_new (obj, type, ref_count, infos));
}
l = g_list_prepend (l, leak_new (obj, type, ref_count, infos));
/* for leaked objects, we take ownership of the object instead of
* reffing ("collecting") it to avoid deadlocks */
g_value_init (&obj_value, leak->type);
/* for leaked objects, we take ownership of the object instead of
* reffing ("collecting") it to avoid deadlocks */
g_value_init (&obj_value, leak->type);
- if (object_is_gst_mini_object (leak->obj))
- g_value_take_boxed (&obj_value, leak->obj);
- else
- g_value_take_object (&obj_value, leak->obj);
+ switch (leak->infos->kind) {
+ case GOBJECT:
+ g_value_take_object (&obj_value, leak->obj);
+ break;
+ case MINI_OBJECT:
+ g_value_take_boxed (&obj_value, leak->obj);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
s = gst_structure_new_empty ("object-alive");
gst_structure_take_value (s, "object", &obj_value);
gst_structure_set (s, "ref-count", G_TYPE_UINT, leak->ref_count,
s = gst_structure_new_empty ("object-alive");
gst_structure_take_value (s, "object", &obj_value);
gst_structure_set (s, "ref-count", G_TYPE_UINT, leak->ref_count,
GstLeaksTracer *self = GST_LEAKS_TRACER (object);
gboolean leaks = FALSE;
GHashTableIter iter;
GstLeaksTracer *self = GST_LEAKS_TRACER (object);
gboolean leaks = FALSE;
GHashTableIter iter;
GST_DEBUG_OBJECT (self, "destroying tracer, checking for leaks");
GST_DEBUG_OBJECT (self, "destroying tracer, checking for leaks");
/* Remove weak references */
g_hash_table_iter_init (&iter, self->objects);
/* Remove weak references */
g_hash_table_iter_init (&iter, self->objects);
- while (g_hash_table_iter_next (&iter, &obj, NULL)) {
- if (object_is_gst_mini_object (obj))
- gst_mini_object_weak_unref (GST_MINI_OBJECT_CAST (obj),
- mini_object_weak_cb, self);
- else
- g_object_weak_unref (obj, object_weak_cb, self);
+ while (g_hash_table_iter_next (&iter, &obj, &infos)) {
+ switch (((ObjectRefingInfos *) infos)->kind) {
+ case GOBJECT:
+ g_object_weak_unref (obj, object_weak_cb, self);
+ break;
+ case MINI_OBJECT:
+ gst_mini_object_weak_unref (GST_MINI_OBJECT_CAST (obj),
+ mini_object_weak_cb, self);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
}
g_clear_pointer (&self->objects, g_hash_table_unref);
}
g_clear_pointer (&self->objects, g_hash_table_unref);