diff --git a/src/app/AttributeCache.cpp b/src/app/AttributeCache.cpp index 349a8563636144..34fe0586ab2efd 100644 --- a/src/app/AttributeCache.cpp +++ b/src/app/AttributeCache.cpp @@ -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(*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)