Skip to content

Commit

Permalink
[darwin-framework-tool] ClusterCommandBridge.h does not release the c…
Browse files Browse the repository at this point in the history
…ustom argument data, making the leak detector complaining
  • Loading branch information
vivien-apple committed Oct 23, 2024
1 parent 5c0c92e commit a9e28c2
Showing 1 changed file with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,8 @@ class ClusterCommand : public ModelCommand {

CHIP_ERROR SendCommand(MTRBaseDevice * _Nonnull device, chip::EndpointId endpointId) override
{
chip::TLV::TLVWriter writer;
chip::TLV::TLVReader reader;

mData = static_cast<uint8_t *>(chip::Platform::MemoryCalloc(sizeof(uint8_t), mDataMaxLen));
VerifyOrReturnError(mData != nullptr, CHIP_ERROR_NO_MEMORY);

writer.Init(mData, mDataMaxLen);

ReturnErrorOnFailure(mPayload.Encode(writer, chip::TLV::AnonymousTag()));
reader.Init(mData, writer.GetLengthWritten());
ReturnErrorOnFailure(reader.Next());

id commandFields = NSObjectFromCHIPTLV(&reader);
if (commandFields == nil) {
return CHIP_ERROR_INTERNAL;
}
id commandFields;
ReturnErrorOnFailure(GetCommandFields(&commandFields));
return ClusterCommand::SendCommand(device, endpointId, mClusterId, mCommandId, commandFields);
}

Expand Down Expand Up @@ -136,6 +122,35 @@ class ClusterCommand : public ModelCommand {
NSError * _Nullable mError = nil;

private:
CHIP_ERROR GetCommandFields(id _Nonnull * _Nonnull outCommandFields)
{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::TLV::TLVWriter writer;
chip::TLV::TLVReader reader;

mData = static_cast<uint8_t *>(chip::Platform::MemoryCalloc(sizeof(uint8_t), mDataMaxLen));
VerifyOrExit(mData != nullptr, err = CHIP_ERROR_NO_MEMORY);

writer.Init(mData, mDataMaxLen);

err = mPayload.Encode(writer, chip::TLV::AnonymousTag());
SuccessOrExit(err);

reader.Init(mData, writer.GetLengthWritten());
err = reader.Next();
SuccessOrExit(err);

*outCommandFields = NSObjectFromCHIPTLV(&reader);
VerifyOrDo(nil != *outCommandFields, err = CHIP_ERROR_INTERNAL);

exit:
if (nullptr != mData) {
chip::Platform::MemoryFree(mData);
mData = nullptr;
}
return err;
}

chip::ClusterId mClusterId;
chip::CommandId mCommandId;

Expand Down

0 comments on commit a9e28c2

Please sign in to comment.