summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2017-05-15 14:32:48 +0300
committerSebastian Dröge <sebastian@centricular.com>2017-05-17 10:40:37 +0300
commitdaa98fc02a7bece11709b485645320c00bcd6599 (patch)
tree5f09f9c1555dbb8d16b3d1020d31bc522f767420
parent30f871d274e8a544779c287a1a4c188f22c2066f (diff)
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
-rw-r--r--gst/gstbus.c6
-rw-r--r--gst/gstclock.c3
-rw-r--r--gst/gstcontrolsource.c20
-rw-r--r--gst/gstsystemclock.c4
-rw-r--r--gst/gsttask.c6
-rw-r--r--gst/gsttaskpool.c5
-rw-r--r--libs/gst/base/gstcollectpads.c6
-rw-r--r--libs/gst/check/gsttestclock.c9
-rw-r--r--libs/gst/controller/gstinterpolationcontrolsource.c8
-rw-r--r--libs/gst/controller/gstlfocontrolsource.c7
-rw-r--r--libs/gst/controller/gsttriggercontrolsource.c8
-rw-r--r--libs/gst/net/gstnetclientclock.c10
-rw-r--r--libs/gst/net/gstptpclock.c14
-rw-r--r--tests/check/gst/gstcontroller.c8
14 files changed, 70 insertions, 44 deletions
diff --git a/gst/gstbus.c b/gst/gstbus.c
index f4039db1c..baccd904c 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 f167bad5a..35d518620 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 30d43993f..1817edce9 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 1fc88a2e5..be9d70fe9 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 d231bd12b..30959f8cd 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 cd0320fb9..8344d9ad8 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 16a239b5d..ad6221119 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 ab90e49d4..d1d2c3001 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 d10bd2b05..4c9f0c8c3 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 36d2d0398..4419a1972 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 438ccb19f..aafa8de26 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 3049ed4a3..2dbd26840 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 79951a3ab..8258b147a 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 ed91ffc3e..092a63de8 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