Skip to content

Commit

Permalink
Fix AttributeCache forwarding callback
Browse files Browse the repository at this point in the history
* Fix forwarded OnAttributeData callback losing data by
  copying the TLV reader before its state changes for cache update.
  • Loading branch information
kpark-apple committed Mar 23, 2022
1 parent d57c3b3 commit f6599d4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/app/AttributeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,23 @@ void AttributeCache::OnAttributeData(const ConcreteDataAttributePath & aPath, TL
//
VerifyOrDie(!aPath.IsListItemOperation());

// Copy the reader for forwarding
TLV::TLVReader * pDataCopy = nullptr;
if (apData)
{
pDataCopy = Platform::New<TLV::TLVReader>(*apData);
}

UpdateCache(aPath, apData, aStatus);

//
// Forward the call through.
//
mCallback.OnAttributeData(aPath, apData, aStatus);
mCallback.OnAttributeData(aPath, pDataCopy, aStatus);
if (pDataCopy)
{
Platform::Delete(pDataCopy);
}
}

CHIP_ERROR AttributeCache::Get(const ConcreteAttributePath & path, TLV::TLVReader & reader)
Expand Down

0 comments on commit f6599d4

Please sign in to comment.