From c97da797c5d579d9bd0806ba00f27a61aa6d05b7 Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo Date: Fri, 14 Apr 2023 11:47:20 +0900 Subject: [PATCH] modify --- src/darwin/Framework/CHIP/MTRBaseDevice.mm | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRBaseDevice.mm b/src/darwin/Framework/CHIP/MTRBaseDevice.mm index bf88e6e333d676..6f1d8ec301bc75 100644 --- a/src/darwin/Framework/CHIP/MTRBaseDevice.mm +++ b/src/darwin/Framework/CHIP/MTRBaseDevice.mm @@ -996,7 +996,13 @@ - (void)readAttributePaths:(NSArray * _Nullable)attri size_t count = 0; eventPathParamsList = static_cast(Platform::MemoryCalloc([events count], sizeof(EventPathParams))); - VerifyOrReturnError(eventPathParamsList != nullptr, CHIP_ERROR_NO_MEMORY); + if (eventPathParamsList == nullptr) { + if (attributePathParamsList != nullptr) { + Platform::MemoryFree(attributePathParamsList); + attributePathParamsList = nullptr; + } + return CHIP_ERROR_NO_MEMORY; + } for (MTREventRequestPath * event in events) { [event convertToEventPathParams:eventPathParamsList[count++]]; } @@ -1396,11 +1402,9 @@ - (void)subscribeToAttributePaths:(NSArray * _Nullabl 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]); - }); - } + dispatch_async(queue, ^{ + reportHandler(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_NO_MEMORY]); + }); return; } for (MTRAttributeRequestPath * attribute in attributes) { @@ -1412,11 +1416,9 @@ - (void)subscribeToAttributePaths:(NSArray * _Nullabl 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]); - }); - } + dispatch_async(queue, ^{ + reportHandler(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_NO_MEMORY]); + }); return; } for (MTREventRequestPath * event in events) {