Fixed potential use-after-free on detached threads

This could sometimes cause REAPER's plugin scanning to crash when the
stars aligned in the wrong way since the stop token would no longer
exist.
This commit is contained in:
Robbert van der Helm
2020-09-28 22:29:10 +02:00
parent 401824ae54
commit 32b3e106b1
3 changed files with 14 additions and 3 deletions
+3
View File
@@ -10,6 +10,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).
### Fixed
- Fixed a potential crash that could happen if the host would unload a plugin
immediately after its initialization. This issue affected the plugin scanning
in _REAPER_.
- Fixed parsing order of `yabridge.toml`. Sections were not always read from top
to bottom like they should be, which could cause incorrect setting overrides.
- Fixed an initialization error when using plugin groups for plugins that are
+2 -3
View File
@@ -91,7 +91,7 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback)
// when it is not. The alternative would be to rewrite this to using
// `async_accept`, Boost.Asio timers, and another IO context, but I feel
// like this a much simpler solution.
std::jthread host_guard_handler([&](std::stop_token st) {
host_guard_handler = std::jthread([&](std::stop_token st) {
using namespace std::literals::chrono_literals;
while (!st.stop_requested()) {
@@ -102,7 +102,7 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback)
std::terminate();
}
std::this_thread::sleep_for(1s);
std::this_thread::sleep_for(20ms);
}
});
#endif
@@ -118,7 +118,6 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback)
#ifndef WITH_WINEDBG
host_guard_handler.request_stop();
host_guard_handler.detach();
#endif
// There's no need to keep the socket endpoint file around after accepting
+9
View File
@@ -208,6 +208,15 @@ class PluginBridge {
*/
std::unique_ptr<HostProcess> vst_host;
/**
* A thread used during the initialisation process to terminate listening on
* the sockets if the Wine process cannot start for whatever reason. This
* has to be defined here instead of in the constructor we can't simply
* detach the thread as it has to check whether the VST host is still
* running.
*/
std::jthread host_guard_handler;
/**
* Whether this process runs with realtime priority. We'll set this _after_
* spawning the Wine process because from my testing running wineserver with