From 6b2207d412d0dd480cc1ada39fde38a047a9cec3 Mon Sep 17 00:00:00 2001 From: pixl Date: Thu, 27 Apr 2023 18:39:34 -0400 Subject: [PATCH] Fix memory error with gesture configs --- src/logid/actions/GestureAction.cpp | 14 ++++++-------- src/logid/actions/gesture/Gesture.cpp | 4 ++-- src/logid/features/HiresScroll.cpp | 6 ++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/logid/actions/GestureAction.cpp b/src/logid/actions/GestureAction.cpp index a7a32ca..fbe6f24 100644 --- a/src/logid/actions/GestureAction.cpp +++ b/src/logid/actions/GestureAction.cpp @@ -77,8 +77,7 @@ GestureAction::GestureAction(Device* dev, config::GestureAction& config, Action(dev, interface_name, { { - {"SetGesture", {this, &GestureAction::setGesture, - {"direction", "type"}}} + {"SetGesture", {this, &GestureAction::setGesture, {"direction", "type"}}} }, {}, {} @@ -86,14 +85,13 @@ GestureAction::GestureAction(Device* dev, config::GestureAction& config, _node(parent->make_child("gestures")), _config(config) { if (_config.gestures.has_value()) { auto& gestures = _config.gestures.value(); - for (auto& x: gestures) { + for (auto&& x: gestures) { try { auto direction = toDirection(x.first); - _gestures.emplace(direction, - Gesture::makeGesture( - dev, x.second, - _node->make_child( - fromDirection(direction)))); + _gestures.emplace( + direction,Gesture::makeGesture( + dev, x.second, + _node->make_child(fromDirection(direction)))); } catch (std::invalid_argument& e) { logPrintf(WARN, "%s is not a direction", x.first.c_str()); } diff --git a/src/logid/actions/gesture/Gesture.cpp b/src/logid/actions/gesture/Gesture.cpp index 45d3b47..7e65d8e 100644 --- a/src/logid/actions/gesture/Gesture.cpp +++ b/src/logid/actions/gesture/Gesture.cpp @@ -50,10 +50,10 @@ namespace { template std::shared_ptr _makeGesture( - Device* device, T gesture, + Device* device, T& gesture, const std::shared_ptr& parent) { return parent->make_interface::type>( - device, gesture, parent); + device, std::forward(gesture), parent); } } diff --git a/src/logid/features/HiresScroll.cpp b/src/logid/features/HiresScroll.cpp index fa321c2..84fa42f 100644 --- a/src/logid/features/HiresScroll.cpp +++ b/src/logid/features/HiresScroll.cpp @@ -112,11 +112,9 @@ void HiresScroll::_makeAction(std::shared_ptr& gesture, gesture = actions::Gesture::makeGesture(_device, config.value(), _node->make_child(direction)); try { - auto axis = std::dynamic_pointer_cast( - gesture); + auto axis = std::dynamic_pointer_cast(gesture); if (axis) - axis->setHiresMultiplier( - _hires_scroll->getCapabilities().multiplier); + axis->setHiresMultiplier(_hires_scroll->getCapabilities().multiplier); } catch (std::bad_cast& e) {} if (gesture) gesture->press(true);