From 4c69001a0acef9a77c5963708ecc67262c2b26bd Mon Sep 17 00:00:00 2001 From: BoB13-Matter Date: Tue, 3 Dec 2024 00:26:18 +0900 Subject: [PATCH] Ensure SYSTEM_STATS_INCREMENT only on successful Timer allocation in SystemTimer.h (#36690) * Fix: Ensure SYSTEM_STATS_INCREMENT only on successful Timer allocation * Update SystemTimer.h --- src/system/SystemTimer.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/system/SystemTimer.h b/src/system/SystemTimer.h index 698be028ce029a..99c3d8620f194f 100644 --- a/src/system/SystemTimer.h +++ b/src/system/SystemTimer.h @@ -204,7 +204,11 @@ class TimerPool Timer * Create(Layer & systemLayer, System::Clock::Timestamp awakenTime, TimerCompleteCallback onComplete, void * appState) { Timer * timer = mTimerPool.CreateObject(systemLayer, awakenTime, onComplete, appState); - SYSTEM_STATS_INCREMENT(Stats::kSystemLayer_NumTimers); + if (timer != nullptr) + { + SYSTEM_STATS_INCREMENT(Stats::kSystemLayer_NumTimers); + } + return timer; }