gst: Don't ref_sink() GstObject subclasses in instance_init/constructor

This is something bindings can't handle and it causes leaks. Instead
move the ref_sink() to the explicit, new() constructors.

This means that abstract classes, and anything that can have subclasses,
will have to do ref_sink() in their new() function now. Specifically
this affects GstClock and GstControlSource.

https://bugzilla.gnome.org/show_bug.cgi?id=743062
This commit is contained in:
Sebastian Dröge 2017-05-15 14:32:48 +03:00
parent 30f871d274
commit daa98fc02a
14 changed files with 70 additions and 44 deletions

View file

@ -229,9 +229,6 @@ gst_bus_init (GstBus * bus)
g_mutex_init (&bus->priv->queue_lock); g_mutex_init (&bus->priv->queue_lock);
bus->priv->queue = gst_atomic_queue_new (32); bus->priv->queue = gst_atomic_queue_new (32);
/* clear floating flag */
gst_object_ref_sink (bus);
GST_DEBUG_OBJECT (bus, "created"); GST_DEBUG_OBJECT (bus, "created");
} }
@ -288,6 +285,9 @@ gst_bus_new (void)
result = g_object_new (gst_bus_get_type (), NULL); result = g_object_new (gst_bus_get_type (), NULL);
GST_DEBUG_OBJECT (result, "created new bus"); GST_DEBUG_OBJECT (result, "created new bus");
/* clear floating flag */
gst_object_ref_sink (result);
return result; return result;
} }

View file

@ -741,9 +741,6 @@ gst_clock_init (GstClock * clock)
priv->timeout = DEFAULT_TIMEOUT; priv->timeout = DEFAULT_TIMEOUT;
priv->times = g_new0 (GstClockTime, 4 * priv->window_size); priv->times = g_new0 (GstClockTime, 4 * priv->window_size);
priv->times_temp = priv->times + 2 * priv->window_size; priv->times_temp = priv->times + 2 * priv->window_size;
/* clear floating flag */
gst_object_ref_sink (clock);
} }
static void static void

View file

@ -57,15 +57,9 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstControlSource, gst_control_source, G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstControlSource, gst_control_source,
GST_TYPE_OBJECT, _do_init); GST_TYPE_OBJECT, _do_init);
static GObject *gst_control_source_constructor (GType type,
guint n_construct_params, GObjectConstructParam * construct_params);
static void static void
gst_control_source_class_init (GstControlSourceClass * klass) gst_control_source_class_init (GstControlSourceClass * klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->constructor = gst_control_source_constructor;
} }
static void static void
@ -75,20 +69,6 @@ gst_control_source_init (GstControlSource * self)
self->get_value_array = NULL; self->get_value_array = NULL;
} }
static GObject *
gst_control_source_constructor (GType type, guint n_construct_params,
GObjectConstructParam * construct_params)
{
GObject *self;
self =
G_OBJECT_CLASS (gst_control_source_parent_class)->constructor (type,
n_construct_params, construct_params);
gst_object_ref_sink (self);
return self;
}
/** /**
* gst_control_source_get_value: (method) * gst_control_source_get_value: (method)
* @self: the #GstControlSource object * @self: the #GstControlSource object

View file

@ -355,8 +355,8 @@ gst_system_clock_obtain (void)
clock = g_object_new (GST_TYPE_SYSTEM_CLOCK, clock = g_object_new (GST_TYPE_SYSTEM_CLOCK,
"name", "GstSystemClock", NULL); "name", "GstSystemClock", NULL);
g_assert (!g_object_is_floating (G_OBJECT (clock))); /* Clear floating flag */
gst_object_ref_sink (clock);
_the_system_clock = clock; _the_system_clock = clock;
g_mutex_unlock (&_gst_sysclock_mutex); g_mutex_unlock (&_gst_sysclock_mutex);
} else { } else {

View file

@ -203,9 +203,6 @@ gst_task_init (GstTask * task)
g_mutex_lock (&pool_lock); g_mutex_lock (&pool_lock);
task->priv->pool = gst_object_ref (klass->pool); task->priv->pool = gst_object_ref (klass->pool);
g_mutex_unlock (&pool_lock); g_mutex_unlock (&pool_lock);
/* clear floating flag */
gst_object_ref_sink (task);
} }
static void static void
@ -430,6 +427,9 @@ gst_task_new (GstTaskFunction func, gpointer user_data, GDestroyNotify notify)
GST_DEBUG ("Created task %p", task); GST_DEBUG ("Created task %p", task);
/* clear floating flag */
gst_object_ref_sink (task);
return task; return task;
} }

View file

@ -140,8 +140,6 @@ gst_task_pool_class_init (GstTaskPoolClass * klass)
static void static void
gst_task_pool_init (GstTaskPool * pool) gst_task_pool_init (GstTaskPool * pool)
{ {
/* clear floating flag */
gst_object_ref_sink (pool);
} }
#ifndef GST_DISABLE_GST_DEBUG #ifndef GST_DISABLE_GST_DEBUG
@ -168,6 +166,9 @@ gst_task_pool_new (void)
pool = g_object_new (GST_TYPE_TASK_POOL, NULL); pool = g_object_new (GST_TYPE_TASK_POOL, NULL);
/* clear floating flag */
gst_object_ref_sink (pool);
return pool; return pool;
} }

View file

@ -255,9 +255,6 @@ gst_collect_pads_init (GstCollectPads * pads)
pads->priv->seeking = FALSE; pads->priv->seeking = FALSE;
pads->priv->pending_flush_start = FALSE; pads->priv->pending_flush_start = FALSE;
pads->priv->pending_flush_stop = FALSE; pads->priv->pending_flush_stop = FALSE;
/* clear floating flag */
gst_object_ref_sink (pads);
} }
static void static void
@ -297,6 +294,9 @@ gst_collect_pads_new (void)
newcoll = g_object_new (GST_TYPE_COLLECT_PADS, NULL); newcoll = g_object_new (GST_TYPE_COLLECT_PADS, NULL);
/* clear floating flag */
gst_object_ref_sink (newcoll);
return newcoll; return newcoll;
} }

View file

@ -691,8 +691,15 @@ gst_test_clock_new (void)
GstClock * GstClock *
gst_test_clock_new_with_start_time (GstClockTime start_time) gst_test_clock_new_with_start_time (GstClockTime start_time)
{ {
GstClock *clock;
g_assert_cmpuint (start_time, !=, GST_CLOCK_TIME_NONE); g_assert_cmpuint (start_time, !=, GST_CLOCK_TIME_NONE);
return g_object_new (GST_TYPE_TEST_CLOCK, "start-time", start_time, NULL); clock = g_object_new (GST_TYPE_TEST_CLOCK, "start-time", start_time, NULL);
/* Clear floating flag */
gst_object_ref_sink (clock);
return clock;
} }
/** /**

View file

@ -644,7 +644,13 @@ struct _GstInterpolationControlSourcePrivate
GstControlSource * GstControlSource *
gst_interpolation_control_source_new (void) gst_interpolation_control_source_new (void)
{ {
return g_object_new (GST_TYPE_INTERPOLATION_CONTROL_SOURCE, NULL); GstControlSource *csource =
g_object_new (GST_TYPE_INTERPOLATION_CONTROL_SOURCE, NULL);
/* Clear floating flag */
gst_object_ref_sink (csource);
return csource;
} }
static gboolean static gboolean

View file

@ -398,7 +398,12 @@ gst_lfo_control_source_reset (GstLFOControlSource * self)
GstControlSource * GstControlSource *
gst_lfo_control_source_new (void) gst_lfo_control_source_new (void)
{ {
return g_object_new (GST_TYPE_LFO_CONTROL_SOURCE, NULL); GstControlSource *csource = g_object_new (GST_TYPE_LFO_CONTROL_SOURCE, NULL);
/* Clear floating flag */
gst_object_ref_sink (csource);
return csource;
} }
static gboolean static gboolean

View file

@ -188,7 +188,13 @@ G_DEFINE_TYPE_WITH_CODE (GstTriggerControlSource, gst_trigger_control_source,
GstControlSource * GstControlSource *
gst_trigger_control_source_new (void) gst_trigger_control_source_new (void)
{ {
return g_object_new (GST_TYPE_TRIGGER_CONTROL_SOURCE, NULL); GstControlSource *csource =
g_object_new (GST_TYPE_TRIGGER_CONTROL_SOURCE, NULL);
/* Clear floating flag */
gst_object_ref_sink (csource);
return csource;
} }
static void static void

View file

@ -1332,6 +1332,7 @@ gst_net_client_clock_constructed (GObject * object)
g_object_new (GST_TYPE_NET_CLIENT_INTERNAL_CLOCK, "address", g_object_new (GST_TYPE_NET_CLIENT_INTERNAL_CLOCK, "address",
self->priv->address, "port", self->priv->port, "is-ntp", self->priv->address, "port", self->priv->port, "is-ntp",
self->priv->is_ntp, NULL); self->priv->is_ntp, NULL);
gst_object_ref_sink (cache->clock);
clocks = g_list_prepend (clocks, cache); clocks = g_list_prepend (clocks, cache);
/* Not actually leaked but is cached for a while before being disposed, /* Not actually leaked but is cached for a while before being disposed,
@ -1382,7 +1383,7 @@ gst_net_client_clock_get_internal_time (GstClock * clock)
* provided by the #GstNetTimeProvider on @remote_address and * provided by the #GstNetTimeProvider on @remote_address and
* @remote_port. * @remote_port.
* *
* Returns: a new #GstClock that receives a time from the remote * Returns: (transfer full): a new #GstClock that receives a time from the remote
* clock. * clock.
*/ */
GstClock * GstClock *
@ -1400,6 +1401,9 @@ gst_net_client_clock_new (const gchar * name, const gchar * remote_address,
g_object_new (GST_TYPE_NET_CLIENT_CLOCK, "name", name, "address", g_object_new (GST_TYPE_NET_CLIENT_CLOCK, "name", name, "address",
remote_address, "port", remote_port, "base-time", base_time, NULL); remote_address, "port", remote_port, "base-time", base_time, NULL);
/* Clear floating flag */
gst_object_ref_sink (ret);
return ret; return ret;
} }
@ -1426,7 +1430,7 @@ gst_ntp_clock_init (GstNtpClock * self)
* Create a new #GstNtpClock that will report the time provided by * Create a new #GstNtpClock that will report the time provided by
* the NTPv4 server on @remote_address and @remote_port. * the NTPv4 server on @remote_address and @remote_port.
* *
* Returns: a new #GstClock that receives a time from the remote * Returns: (transfer full): a new #GstClock that receives a time from the remote
* clock. * clock.
* *
* Since: 1.6 * Since: 1.6
@ -1446,5 +1450,7 @@ gst_ntp_clock_new (const gchar * name, const gchar * remote_address,
g_object_new (GST_TYPE_NTP_CLOCK, "name", name, "address", remote_address, g_object_new (GST_TYPE_NTP_CLOCK, "name", name, "address", remote_address,
"port", remote_port, "base-time", base_time, NULL); "port", remote_port, "base-time", base_time, NULL);
gst_object_ref_sink (ret);
return ret; return ret;
} }

View file

@ -855,6 +855,7 @@ handle_announce_message (PtpMessage * msg, GstClockTime receive_time)
clock_name = g_strdup_printf ("ptp-clock-%u", domain->domain); clock_name = g_strdup_printf ("ptp-clock-%u", domain->domain);
domain->domain_clock = domain->domain_clock =
g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", clock_name, NULL); g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", clock_name, NULL);
gst_object_ref_sink (domain->domain_clock);
g_free (clock_name); g_free (clock_name);
g_queue_init (&domain->pending_syncs); g_queue_init (&domain->pending_syncs);
domain->last_path_delays_missing = 9; domain->last_path_delays_missing = 9;
@ -1445,6 +1446,7 @@ handle_sync_message (PtpMessage * msg, GstClockTime receive_time)
clock_name = g_strdup_printf ("ptp-clock-%u", domain->domain); clock_name = g_strdup_printf ("ptp-clock-%u", domain->domain);
domain->domain_clock = domain->domain_clock =
g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", clock_name, NULL); g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", clock_name, NULL);
gst_object_ref_sink (domain->domain_clock);
g_free (clock_name); g_free (clock_name);
g_queue_init (&domain->pending_syncs); g_queue_init (&domain->pending_syncs);
domain->last_path_delays_missing = 9; domain->last_path_delays_missing = 9;
@ -2111,6 +2113,7 @@ gst_ptp_init (guint64 clock_id, gchar ** interfaces)
observation_system_clock = observation_system_clock =
g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", "ptp-observation-clock", g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", "ptp-observation-clock",
NULL); NULL);
gst_object_ref_sink (observation_system_clock);
initted = TRUE; initted = TRUE;
@ -2510,11 +2513,15 @@ gst_ptp_clock_get_internal_time (GstClock * clock)
* check this with gst_clock_wait_for_sync(), the GstClock::synced signal and * check this with gst_clock_wait_for_sync(), the GstClock::synced signal and
* gst_clock_is_synced(). * gst_clock_is_synced().
* *
* Returns: (transfer full): A new #GstClock
*
* Since: 1.6 * Since: 1.6
*/ */
GstClock * GstClock *
gst_ptp_clock_new (const gchar * name, guint domain) gst_ptp_clock_new (const gchar * name, guint domain)
{ {
GstClock *clock;
g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (domain <= G_MAXUINT8, NULL); g_return_val_if_fail (domain <= G_MAXUINT8, NULL);
@ -2523,8 +2530,13 @@ gst_ptp_clock_new (const gchar * name, guint domain)
return NULL; return NULL;
} }
return g_object_new (GST_TYPE_PTP_CLOCK, "name", name, "domain", domain, clock = g_object_new (GST_TYPE_PTP_CLOCK, "name", name, "domain", domain,
NULL); NULL);
/* Clear floating flag */
gst_object_ref_sink (clock);
return clock;
} }
typedef struct typedef struct

View file

@ -231,7 +231,13 @@ static GType gst_test_control_source_get_type (void);
static GstTestControlSource * static GstTestControlSource *
gst_test_control_source_new (void) gst_test_control_source_new (void)
{ {
return g_object_new (GST_TYPE_TEST_CONTROL_SOURCE, NULL); GstTestControlSource *csource =
g_object_new (GST_TYPE_TEST_CONTROL_SOURCE, NULL);
/* Clear floating flag */
gst_object_ref_sink (csource);
return csource;
} }
static gboolean static gboolean