From 2ab0343a75e165684dba64aea4b54a5abbe8086c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 15 May 2016 12:10:09 +0200 Subject: api/shortcuts: fix use-after-free on Linux and OSX Issue: #349 Valgrind: yes --- opentrack/shortcuts.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'opentrack/shortcuts.cpp') diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index ca069b2a..2caa1790 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -95,12 +95,15 @@ void Shortcuts::reload(const std::vector> &keys const auto& kk = keys_[i]; const key_opts& opts = std::get<0>(kk); const bool held = std::get<2>(kk); - auto& fun = std::get<1>(kk); + auto fun = std::get<1>(kk); K k; bind_keyboard_shortcut(k, opts, held); - keys.push_back(tt(k, fun, held)); + keys.push_back(tt(k, [=](bool) -> void { fun(true); }, held)); + const int idx = keys.size() - 1; + tt& kk_ = keys[idx]; + auto& fn = std::get<1>(kk_); #ifndef _WIN32 - connect(k.get(), &QxtGlobalShortcut::activated, [&]() -> void { fun(true); }); + connect(k.get(), &QxtGlobalShortcut::activated, [=]() -> void { fn(true); }); #endif } } -- cgit v1.2.3