From 32ef52f06a4df3b91055724627d3cd13111e35ba Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 3 Dec 2025 12:40:41 -0800 Subject: [PATCH] [mdns] handle allocation failure in `RxMessage::Init()` (#12193) This commit updates `RxMessage::Init()` to handle failures when reserving capacity for the questions array. Previously, an allocation failure would trigger an assertion. By switching to `SuccessOrExit`, the method can now gracefully handle the allocation failure by returning an error and dropping the message. This aligns with the general error handling strategy for received messages and makes the implementation more robust against out-of-memory conditions. --- src/core/net/mdns.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/net/mdns.cpp b/src/core/net/mdns.cpp index 606bcda58..949812116 100644 --- a/src/core/net/mdns.cpp +++ b/src/core/net/mdns.cpp @@ -4229,7 +4229,7 @@ Error Core::RxMessage::Init(Instance &aInstance, mStartOffset[kQuestionSection] = offset; - SuccessOrAssert(mQuestions.ReserveCapacity(mRecordCounts.GetFor(kQuestionSection))); + SuccessOrExit(error = mQuestions.ReserveCapacity(mRecordCounts.GetFor(kQuestionSection))); for (numRecords = mRecordCounts.GetFor(kQuestionSection); numRecords > 0; numRecords--) {