From daa98fc02a7bece11709b485645320c00bcd6599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 15 May 2017 14:32:48 +0300 Subject: [PATCH] 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 --- gst/gstbus.c | 6 +++--- gst/gstclock.c | 3 --- gst/gstcontrolsource.c | 20 ------------------- gst/gstsystemclock.c | 4 ++-- gst/gsttask.c | 6 +++--- gst/gsttaskpool.c | 5 +++-- libs/gst/base/gstcollectpads.c | 6 +++--- libs/gst/check/gsttestclock.c | 9 ++++++++- .../gstinterpolationcontrolsource.c | 8 +++++++- libs/gst/controller/gstlfocontrolsource.c | 7 ++++++- libs/gst/controller/gsttriggercontrolsource.c | 8 +++++++- libs/gst/net/gstnetclientclock.c | 10 ++++++++-- libs/gst/net/gstptpclock.c | 14 ++++++++++++- tests/check/gst/gstcontroller.c | 8 +++++++- 14 files changed, 70 insertions(+), 44 deletions(-) diff --git a/gst/gstbus.c b/gst/gstbus.c index f4039db1cf..baccd904ca 100644 --- a/gst/gstbus.c +++ b/gst/gstbus.c @@ -229,9 +229,6 @@ gst_bus_init (GstBus * bus) g_mutex_init (&bus->priv->queue_lock); bus->priv->queue = gst_atomic_queue_new (32); - /* clear floating flag */ - gst_object_ref_sink (bus); - GST_DEBUG_OBJECT (bus, "created"); } @@ -288,6 +285,9 @@ gst_bus_new (void) result = g_object_new (gst_bus_get_type (), NULL); GST_DEBUG_OBJECT (result, "created new bus"); + /* clear floating flag */ + gst_object_ref_sink (result); + return result; } diff --git a/gst/gstclock.c b/gst/gstclock.c index f167bad5a9..35d5186209 100644 --- a/gst/gstclock.c +++ b/gst/gstclock.c @@ -741,9 +741,6 @@ gst_clock_init (GstClock * clock) priv->timeout = DEFAULT_TIMEOUT; priv->times = g_new0 (GstClockTime, 4 * priv->window_size); priv->times_temp = priv->times + 2 * priv->window_size; - - /* clear floating flag */ - gst_object_ref_sink (clock); } static void diff --git a/gst/gstcontrolsource.c b/gst/gstcontrolsource.c index 30d43993fa..1817edce96 100644 --- a/gst/gstcontrolsource.c +++ b/gst/gstcontrolsource.c @@ -57,15 +57,9 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstControlSource, gst_control_source, GST_TYPE_OBJECT, _do_init); -static GObject *gst_control_source_constructor (GType type, - guint n_construct_params, GObjectConstructParam * construct_params); - static void gst_control_source_class_init (GstControlSourceClass * klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->constructor = gst_control_source_constructor; } static void @@ -75,20 +69,6 @@ gst_control_source_init (GstControlSource * self) 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) * @self: the #GstControlSource object diff --git a/gst/gstsystemclock.c b/gst/gstsystemclock.c index 1fc88a2e54..be9d70fe9d 100644 --- a/gst/gstsystemclock.c +++ b/gst/gstsystemclock.c @@ -355,8 +355,8 @@ gst_system_clock_obtain (void) clock = g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", "GstSystemClock", NULL); - g_assert (!g_object_is_floating (G_OBJECT (clock))); - + /* Clear floating flag */ + gst_object_ref_sink (clock); _the_system_clock = clock; g_mutex_unlock (&_gst_sysclock_mutex); } else { diff --git a/gst/gsttask.c b/gst/gsttask.c index d231bd12b9..30959f8cdb 100644 --- a/gst/gsttask.c +++ b/gst/gsttask.c @@ -203,9 +203,6 @@ gst_task_init (GstTask * task) g_mutex_lock (&pool_lock); task->priv->pool = gst_object_ref (klass->pool); g_mutex_unlock (&pool_lock); - - /* clear floating flag */ - gst_object_ref_sink (task); } static void @@ -430,6 +427,9 @@ gst_task_new (GstTaskFunction func, gpointer user_data, GDestroyNotify notify) GST_DEBUG ("Created task %p", task); + /* clear floating flag */ + gst_object_ref_sink (task); + return task; } diff --git a/gst/gsttaskpool.c b/gst/gsttaskpool.c index cd0320fb9d..8344d9ad81 100644 --- a/gst/gsttaskpool.c +++ b/gst/gsttaskpool.c @@ -140,8 +140,6 @@ gst_task_pool_class_init (GstTaskPoolClass * klass) static void gst_task_pool_init (GstTaskPool * pool) { - /* clear floating flag */ - gst_object_ref_sink (pool); } #ifndef GST_DISABLE_GST_DEBUG @@ -168,6 +166,9 @@ gst_task_pool_new (void) pool = g_object_new (GST_TYPE_TASK_POOL, NULL); + /* clear floating flag */ + gst_object_ref_sink (pool); + return pool; } diff --git a/libs/gst/base/gstcollectpads.c b/libs/gst/base/gstcollectpads.c index 16a239b5d3..ad62211192 100644 --- a/libs/gst/base/gstcollectpads.c +++ b/libs/gst/base/gstcollectpads.c @@ -255,9 +255,6 @@ gst_collect_pads_init (GstCollectPads * pads) pads->priv->seeking = FALSE; pads->priv->pending_flush_start = FALSE; pads->priv->pending_flush_stop = FALSE; - - /* clear floating flag */ - gst_object_ref_sink (pads); } static void @@ -297,6 +294,9 @@ gst_collect_pads_new (void) newcoll = g_object_new (GST_TYPE_COLLECT_PADS, NULL); + /* clear floating flag */ + gst_object_ref_sink (newcoll); + return newcoll; } diff --git a/libs/gst/check/gsttestclock.c b/libs/gst/check/gsttestclock.c index ab90e49d4c..d1d2c30011 100644 --- a/libs/gst/check/gsttestclock.c +++ b/libs/gst/check/gsttestclock.c @@ -691,8 +691,15 @@ gst_test_clock_new (void) GstClock * gst_test_clock_new_with_start_time (GstClockTime start_time) { + GstClock *clock; + 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; } /** diff --git a/libs/gst/controller/gstinterpolationcontrolsource.c b/libs/gst/controller/gstinterpolationcontrolsource.c index d10bd2b059..4c9f0c8c34 100644 --- a/libs/gst/controller/gstinterpolationcontrolsource.c +++ b/libs/gst/controller/gstinterpolationcontrolsource.c @@ -644,7 +644,13 @@ struct _GstInterpolationControlSourcePrivate GstControlSource * 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 diff --git a/libs/gst/controller/gstlfocontrolsource.c b/libs/gst/controller/gstlfocontrolsource.c index 36d2d0398a..4419a1972f 100644 --- a/libs/gst/controller/gstlfocontrolsource.c +++ b/libs/gst/controller/gstlfocontrolsource.c @@ -398,7 +398,12 @@ gst_lfo_control_source_reset (GstLFOControlSource * self) GstControlSource * 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 diff --git a/libs/gst/controller/gsttriggercontrolsource.c b/libs/gst/controller/gsttriggercontrolsource.c index 438ccb19fc..aafa8de261 100644 --- a/libs/gst/controller/gsttriggercontrolsource.c +++ b/libs/gst/controller/gsttriggercontrolsource.c @@ -188,7 +188,13 @@ G_DEFINE_TYPE_WITH_CODE (GstTriggerControlSource, gst_trigger_control_source, GstControlSource * 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 diff --git a/libs/gst/net/gstnetclientclock.c b/libs/gst/net/gstnetclientclock.c index 3049ed4a3f..2dbd268403 100644 --- a/libs/gst/net/gstnetclientclock.c +++ b/libs/gst/net/gstnetclientclock.c @@ -1332,6 +1332,7 @@ gst_net_client_clock_constructed (GObject * object) g_object_new (GST_TYPE_NET_CLIENT_INTERNAL_CLOCK, "address", self->priv->address, "port", self->priv->port, "is-ntp", self->priv->is_ntp, NULL); + gst_object_ref_sink (cache->clock); clocks = g_list_prepend (clocks, cache); /* 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 * @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. */ 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", remote_address, "port", remote_port, "base-time", base_time, NULL); + /* Clear floating flag */ + gst_object_ref_sink (ret); + return ret; } @@ -1426,7 +1430,7 @@ gst_ntp_clock_init (GstNtpClock * self) * Create a new #GstNtpClock that will report the time provided by * 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. * * 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, "port", remote_port, "base-time", base_time, NULL); + gst_object_ref_sink (ret); + return ret; } diff --git a/libs/gst/net/gstptpclock.c b/libs/gst/net/gstptpclock.c index 79951a3ab7..8258b147a0 100644 --- a/libs/gst/net/gstptpclock.c +++ b/libs/gst/net/gstptpclock.c @@ -855,6 +855,7 @@ handle_announce_message (PtpMessage * msg, GstClockTime receive_time) clock_name = g_strdup_printf ("ptp-clock-%u", domain->domain); domain->domain_clock = g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", clock_name, NULL); + gst_object_ref_sink (domain->domain_clock); g_free (clock_name); g_queue_init (&domain->pending_syncs); 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); domain->domain_clock = g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", clock_name, NULL); + gst_object_ref_sink (domain->domain_clock); g_free (clock_name); g_queue_init (&domain->pending_syncs); domain->last_path_delays_missing = 9; @@ -2111,6 +2113,7 @@ gst_ptp_init (guint64 clock_id, gchar ** interfaces) observation_system_clock = g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", "ptp-observation-clock", NULL); + gst_object_ref_sink (observation_system_clock); 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 * gst_clock_is_synced(). * + * Returns: (transfer full): A new #GstClock + * * Since: 1.6 */ GstClock * gst_ptp_clock_new (const gchar * name, guint domain) { + GstClock *clock; + g_return_val_if_fail (name != NULL, 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 g_object_new (GST_TYPE_PTP_CLOCK, "name", name, "domain", domain, + clock = g_object_new (GST_TYPE_PTP_CLOCK, "name", name, "domain", domain, NULL); + + /* Clear floating flag */ + gst_object_ref_sink (clock); + + return clock; } typedef struct diff --git a/tests/check/gst/gstcontroller.c b/tests/check/gst/gstcontroller.c index ed91ffc3e6..092a63de8a 100644 --- a/tests/check/gst/gstcontroller.c +++ b/tests/check/gst/gstcontroller.c @@ -231,7 +231,13 @@ static GType gst_test_control_source_get_type (void); static GstTestControlSource * 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