diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-05-15 12:10:09 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-05-15 12:10:09 +0200 |
commit | 2ab0343a75e165684dba64aea4b54a5abbe8086c (patch) | |
tree | 5d561c84c5f49a8b7d6225829b48a2ebf40b9783 /opentrack | |
parent | a880f2ae0460422ed0edc7095ffa209e2d8d9f59 (diff) |
api/shortcuts: fix use-after-free on Linux and OSX
Issue: #349
Valgrind: yes
Diffstat (limited to 'opentrack')
-rw-r--r-- | opentrack/shortcuts.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
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<std::tuple<key_opts&, fun, bool>> &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 } } |