Skip to content

Commit

Permalink
[darwin-framework-tool] WriteAttributeCommandBridge.h does not releas…
Browse files Browse the repository at this point in the history
…e the custom argument data, making the leak detector complaining
  • Loading branch information
vivien-apple committed Oct 23, 2024
1 parent a9e28c2 commit 9fc47ad
Showing 1 changed file with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,8 @@ class WriteAttribute : 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(mAttributeValue.Encode(writer, chip::TLV::AnonymousTag()));
reader.Init(mData, writer.GetLengthWritten());
ReturnErrorOnFailure(reader.Next());

id value = NSObjectFromCHIPTLV(&reader);
if (value == nil) {
return CHIP_ERROR_INTERNAL;
}

id value;
ReturnErrorOnFailure(GetValue(&value));
return WriteAttribute::SendCommand(device, endpointId, mClusterId, mAttributeId, value);
}

Expand Down Expand Up @@ -122,6 +107,35 @@ class WriteAttribute : public ModelCommand {
chip::Optional<uint32_t> mDataVersion;

private:
CHIP_ERROR GetValue(id _Nonnull * _Nonnull outValue)
{
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 = mAttributeValue.Encode(writer, chip::TLV::AnonymousTag());
SuccessOrExit(err);

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

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

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

chip::ClusterId mClusterId;
chip::AttributeId mAttributeId;
CHIP_ERROR mError = CHIP_NO_ERROR;
Expand Down

0 comments on commit 9fc47ad

Please sign in to comment.