Skip to content

Commit 8562520

Browse files
committed
[common_callbacks] fix make_confirmation_callback lifetime issue
The make_confirmation_callback function takes the key argument as const ref, meaning that it'll be bound to an existing QString when the arg is QString, but a temporary QString would be constructed and bound to it when the "key" is not a QString. This is fine during the make_confirmation_callback's scope since const& extend the lifetime of the temporary, but passing that "const&" to a capture list of a lambda that'll be executed later does not extend the lifetime, hence leading to undefined behavior. The patch fixes this issue by taking QString as a value and moving that into the lambda capture. Signed-off-by: Mustafa Kemal Gilor <[email protected]>
1 parent 5130efd commit 8562520

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/client/cli/cmd/common_callbacks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ auto make_iterative_spinner_callback(AnimatedSpinner& spinner, Terminal& term)
7575
}
7676

7777
template <typename Request, typename Reply>
78-
auto make_confirmation_callback(Terminal& term, const QString& key)
78+
auto make_confirmation_callback(Terminal& term, QString key)
7979
{
80-
return [&key, &term](Reply& reply, grpc::ClientReaderWriterInterface<Request, Reply>* client) {
80+
return [key = std::move(key), &term](Reply& reply, grpc::ClientReaderWriterInterface<Request, Reply>* client) {
8181
if (key.startsWith(daemon_settings_root) && key.endsWith(bridged_network_name) && reply.needs_authorization())
8282
{
8383
auto bridged_network = reply.reply_message();

0 commit comments

Comments
 (0)