From 75315b2ee7dec1c9334cf707b0c9cb928f1bff43 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 6 Jan 2023 22:44:49 -0500 Subject: [PATCH] Fix reference to out-of-scope temporary in SetUpCodePairer. The old code used to get a reference to a member of a temporary, but nothing kept the temporary alive (it was not assigned to a named reference or anything), so it went out of scope and got destroyed. And then we were referencing garbage. Explicitly keep references to all the things we are using, so they don't go away on us. --- src/controller/SetUpCodePairer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 57ea06ed403e31..d0979d15e06174 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -491,7 +491,8 @@ void SetUpCodePairer::OnPairingComplete(CHIP_ERROR error) if (CHIP_ERROR_TIMEOUT == error && mCurrentPASEParameters.HasValue()) { const auto & params = mCurrentPASEParameters.Value(); - auto & ip = params.GetPeerAddress().GetIPAddress(); + const auto & peer = params.GetPeerAddress(); + const auto & ip = peer.GetIPAddress(); auto err = Dnssd::Resolver::Instance().ReconfirmRecord(params.mHostName, ip, params.mInterfaceId); if (CHIP_NO_ERROR != err && CHIP_ERROR_NOT_IMPLEMENTED != err) {