Commit a4298e71 authored by Gabriel Margiani's avatar Gabriel Margiani

fix segfault in eventhook on timeout.

parent ccfe762f
......@@ -75,6 +75,7 @@ void p3::eventHook::event_worker() {
}
void p3::eventHook::handle_event(const std::array<std::string, 5>& args) {
std::lock_guard<std::mutex> g(callback_mutex);
for (auto c : callbacks) {
c(args[0], args[1], args[2], args[3], args[4]);
}
......
......@@ -362,6 +362,8 @@ void p3::clientHandler::push_event(
const std::string& a4,
const std::string& a5
) {
if (!push_events_enabled) return;
std::lock_guard<std::recursive_mutex> g(connection_write_mutex);
try {
......@@ -381,16 +383,16 @@ void p3::clientHandler::push_event(
}
connection.send(p3::protocol::ENDTEXT, "End Event", 1);
} catch (p3::perror & e) {
hook.unregister_callback(push_event_callback);
push_events_enabled = false;
std::thread t([this, e] () {
std::lock_guard<std::recursive_mutex> g(connection_write_mutex);
std::thread t([this, e] (auto evc) {
try {
hook.unregister_callback(evc);
std::lock_guard<std::recursive_mutex> g(connection_write_mutex);
connection.send(p3::protocol::ERROR, e.what() + std::string(" - Events disabled."));
} catch (p3::perror & e) {
} catch (p3::perror &) {
return;
}
});
}, push_event_callback);
t.detach();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment