From 22775527d1d8d2abd3ca5f036d4751f1aee4c532 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 9 Jan 2023 10:24:50 -0500 Subject: [PATCH] Fix reference to out-of-scope temporary in SetUpCodePairer. (#24316) 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) {