From 908145ae97481f2e3127328dacc7942eefc1c073 Mon Sep 17 00:00:00 2001 From: yangkq Date: Tue, 24 Oct 2023 16:10:49 +0800 Subject: [PATCH] find entry first, then createObject to avoid too many unreference entry alloced --- src/transport/UnauthenticatedSessionTable.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/transport/UnauthenticatedSessionTable.h b/src/transport/UnauthenticatedSessionTable.h index 29193bc0c4060f..e1ec19cb95eea4 100644 --- a/src/transport/UnauthenticatedSessionTable.h +++ b/src/transport/UnauthenticatedSessionTable.h @@ -213,16 +213,18 @@ class UnauthenticatedSessionTable CHIP_ERROR AllocEntry(UnauthenticatedSession::SessionRole sessionRole, NodeId ephemeralInitiatorNodeID, const ReliableMessageProtocolConfig & config, UnauthenticatedSession *& entry) { - entry = mEntries.CreateObject(sessionRole, ephemeralInitiatorNodeID, config); - if (entry != nullptr) - return CHIP_NO_ERROR; entry = FindLeastRecentUsedEntry(); if (entry == nullptr) { - return CHIP_ERROR_NO_MEMORY; + entry = mEntries.CreateObject(sessionRole, ephemeralInitiatorNodeID, config); + if (entry != nullptr) + return CHIP_NO_ERROR; + else + return CHIP_ERROR_NO_MEMORY; } + ChipLogProgress(ExchangeManager, "Allocated new session. Current session count: %zu", mEntries.Allocated()); mEntries.ResetObject(entry, sessionRole, ephemeralInitiatorNodeID, config); return CHIP_NO_ERROR; }