bus: clear bus->priv->signal_watch immediately when the source is removed
authorMichael Olbrich <m.olbrich@pengutronix.de>
Wed, 24 Jun 2020 05:54:42 +0000 (07:54 +0200)
committerMichael Olbrich <m.olbrich@pengutronix.de>
Wed, 24 Jun 2020 13:08:59 +0000 (15:08 +0200)
commit1206a60bacae7cbd0c793f18ea93bc35eda97da8
tree6c4a3fdd8d31d6bbf878fdac3e9715d2160a4ef0
parent996743ed39df7531b31a5b4b2fdc5d2fe0f0148b
bus: clear bus->priv->signal_watch immediately when the source is removed

There is a race-condition that can trigger the assertion in
gst_bus_add_signal_watch_full():

If gst_bus_add_signal_watch_full() is called immediately after
gst_bus_remove_signal_watch() then bus->priv->signal_watch may still be set
because gst_bus_source_dispose() or gst_bus_source_finalize() was not yet
called.
This happens if the corresponding GMainContext has the source queued for
dispatch. In this case, the following dispatch will only unref and delete
the signal_watch because it was already destroyed. Any pending messages
will remain until a new watch is installed.

So bus->priv->signal_watch can be cleared immediately when the watch is
removed. This avoid the race condition.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/543>
gst/gstbus.c
tests/check/gst/gstbus.c