From 37657fec79367c7d5ddb42c1a9b153a5aa9b9bc2 Mon Sep 17 00:00:00 2001
From: Boris Zbarsky <bzbarsky@apple.com>
Date: Tue, 2 Apr 2024 14:20:28 -0400
Subject: [PATCH] Don't stringify PeerAddress in SendPreparedMessage if not
 logging it.

---
 src/transport/SessionManager.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp
index dfcbd6082fa2db..b821820a120492 100644
--- a/src/transport/SessionManager.cpp
+++ b/src/transport/SessionManager.cpp
@@ -448,10 +448,10 @@ CHIP_ERROR SessionManager::SendPreparedMessage(const SessionHandle & sessionHand
     {
         CHIP_ERROR err = mTransportMgr->SendMessage(*destination, std::move(msgBuf));
 #if CHIP_ERROR_LOGGING
-        char addressStr[Transport::PeerAddress::kMaxToStringSize] = { 0 };
-        destination->ToString(addressStr);
         if (err != CHIP_NO_ERROR)
         {
+            char addressStr[Transport::PeerAddress::kMaxToStringSize] = { 0 };
+            destination->ToString(addressStr);
             ChipLogError(Inet, "SendMessage() to %s failed: %" CHIP_ERROR_FORMAT, addressStr, err.Format());
         }
 #endif // CHIP_ERROR_LOGGING