From 3b76de83ebbca58d0765ccadbd35c2ee1fbd8dd7 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Fri, 14 Jan 2022 23:56:48 -0800 Subject: [PATCH] [commands] Fix ProfiledPIDCommand use-after-free (#3904) Fixes #3903. --- .../src/main/native/include/frc2/command/ProfiledPIDCommand.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h index 48ce6b9b53..d106ad348d 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h @@ -97,7 +97,7 @@ class ProfiledPIDCommand std::initializer_list requirements) : ProfiledPIDCommand( controller, measurementSource, - [&goalSource]() { + [goalSource = std::move(goalSource)]() { return State{goalSource(), Velocity_t{0}}; }, useOutput, requirements) {} @@ -119,7 +119,7 @@ class ProfiledPIDCommand wpi::span requirements = {}) : ProfiledPIDCommand( controller, measurementSource, - [&goalSource]() { + [goalSource = std::move(goalSource)]() { return State{goalSource(), Velocity_t{0}}; }, useOutput, requirements) {}