From 994c73e3f0701aeea436eb3b39cabae0490f4cde Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo Date: Thu, 13 Apr 2023 15:09:24 +0900 Subject: [PATCH] Add subscribe null check --- src/darwin/Framework/CHIP/MTRBaseDevice.mm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/darwin/Framework/CHIP/MTRBaseDevice.mm b/src/darwin/Framework/CHIP/MTRBaseDevice.mm index 2c5ca6c715aba3..bf88e6e333d676 100644 --- a/src/darwin/Framework/CHIP/MTRBaseDevice.mm +++ b/src/darwin/Framework/CHIP/MTRBaseDevice.mm @@ -1395,6 +1395,14 @@ - (void)subscribeToAttributePaths:(NSArray * _Nullabl if (attributes != nil) { container.pathParams = static_cast( Platform::MemoryCalloc([attributes count], sizeof(AttributePathParams))); + if (container.pathParams == nullptr) { + if (reportHandler) { + dispatch_async(queue, ^{ + reportHandler(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_NO_MEMORY]); + }); + } + return; + } for (MTRAttributeRequestPath * attribute in attributes) { [attribute convertToAttributePathParams:container.pathParams[attributePathSize++]]; } @@ -1403,6 +1411,14 @@ - (void)subscribeToAttributePaths:(NSArray * _Nullabl if (events != nil) { container.eventPathParams = static_cast(Platform::MemoryCalloc([events count], sizeof(EventPathParams))); + if (container.eventPathParams == nullptr) { + if (reportHandler) { + dispatch_async(queue, ^{ + reportHandler(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_NO_MEMORY]); + }); + } + return; + } for (MTREventRequestPath * event in events) { [event convertToEventPathParams:container.eventPathParams[eventPathSize++]]; }