gnetworkmonitor: Fix use-after-free when using from another thread

When using g_network_monitor_get_default() from another thread, it’s
possible for network-changed events to be processed after an instance of
GNetworkMonitor has been disposed, causing use-after-free problems.

Fix that by moving some of the initialisation into the GInitable.init()
chain, rather than in a main context idle callback.

This includes a unit test which probabilistically reproduces the bug
(but can’t do so deterministically due to it being a race condition).

Commit amended by Philip Withnall <withnall@endlessm.com> before
pushing.

https://bugzilla.gnome.org/show_bug.cgi?id=793727
This commit is contained in:
Milan Crha
2018-04-10 15:27:00 +00:00
committed by Philip Withnall
parent 24e80aac1f
commit ca0add4b8a
7 changed files with 122 additions and 18 deletions

View File

@@ -49,6 +49,7 @@ test_programs = \
monitor \
network-address \
network-monitor \
network-monitor-race \
permission \
pollable \
proxy-test \