mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-26 18:20:44 +00:00
discoverer: Keep a ref for the async timeout callback
This makes sure we maintain a ref on the discoverer object while the async timeout callback is alive to prevent a potential crash if the object is freed while the callback is pending. https://bugzilla.gnome.org/show_bug.cgi?id=641706
This commit is contained in:
parent
40c4fe8fbe
commit
8d2b69384a
1 changed files with 21 additions and 1 deletions
|
@ -982,14 +982,34 @@ discoverer_collect (GstDiscoverer * dc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
get_async_cb (gpointer cb_data, GSource * source, GSourceFunc * func,
|
||||||
|
gpointer * data)
|
||||||
|
{
|
||||||
|
*func = (GSourceFunc) async_timeout_cb;
|
||||||
|
*data = cb_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wrapper since GSourceCallbackFuncs don't expect a return value from ref() */
|
||||||
|
static void
|
||||||
|
_void_g_object_ref (gpointer object)
|
||||||
|
{
|
||||||
|
g_object_ref (G_OBJECT (object));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_current_async (GstDiscoverer * dc)
|
handle_current_async (GstDiscoverer * dc)
|
||||||
{
|
{
|
||||||
GSource *source;
|
GSource *source;
|
||||||
|
static GSourceCallbackFuncs cb_funcs = {
|
||||||
|
.ref = _void_g_object_ref,
|
||||||
|
.unref = g_object_unref,
|
||||||
|
.get = get_async_cb,
|
||||||
|
};
|
||||||
|
|
||||||
/* Attach a timeout to the main context */
|
/* Attach a timeout to the main context */
|
||||||
source = g_timeout_source_new (dc->priv->timeout / GST_MSECOND);
|
source = g_timeout_source_new (dc->priv->timeout / GST_MSECOND);
|
||||||
g_source_set_callback (source, (GSourceFunc) async_timeout_cb, dc, NULL);
|
g_source_set_callback_indirect (source, g_object_ref (dc), &cb_funcs);
|
||||||
dc->priv->timeoutid = g_source_attach (source, dc->priv->ctx);
|
dc->priv->timeoutid = g_source_attach (source, dc->priv->ctx);
|
||||||
g_source_unref (source);
|
g_source_unref (source);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue