Skip to content

Commit

Permalink
Adjust the logic to release UserLabelIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Mar 29, 2022
1 parent e9382f7 commit f9e7187
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/app/clusters/user-label-server/user-label-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,27 @@ CHIP_ERROR UserLabelAttrAccess::ReadLabelList(EndpointId endpoint, AttributeValu

DeviceLayer::DeviceInfoProvider::UserLabelIterator * it = DeviceLayer::GetDeviceInfoProvider()->IterateUserLabel(endpoint);

if (it && it->Count() > 0)
if (it)
{
err = aEncoder.EncodeList([&it](const auto & encoder) -> CHIP_ERROR {
CHIP_ERROR error = CHIP_NO_ERROR;
UserLabel::Structs::LabelStruct::Type userlabel;
if (it->Count() > 0)
{
err = aEncoder.EncodeList([&it](const auto & encoder) -> CHIP_ERROR {
UserLabel::Structs::LabelStruct::Type userlabel;

while (it->Next(userlabel))
{
SuccessOrExit(error = encoder.Encode(userlabel));
}
while (it->Next(userlabel))
{
ReturnErrorOnFailure(encoder.Encode(userlabel));
}

exit:
it->Release();
return CHIP_NO_ERROR;
});
}
else
{
err = aEncoder.EncodeEmptyList();
}

return error;
});
it->Release();
}
else
{
Expand Down

0 comments on commit f9e7187

Please sign in to comment.