Skip to content

Commit

Permalink
Revert "[nrf fromtree] [app] Fix DeferredAttributePersister memory le…
Browse files Browse the repository at this point in the history
…ak (project-chip#31075)"

This reverts commit e79b0cf.
  • Loading branch information
kkasperczyk-no committed May 8, 2024
1 parent 15207ca commit 5251d62
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/app/DeferredAttributePersistenceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void DeferredAttribute::Flush(AttributePersistenceProvider & persister)
{
VerifyOrReturn(IsArmed());
persister.WriteValue(mPath, ByteSpan(mValue.Get(), mValue.AllocatedSize()));
mValue.Free();
mValue.Release();
}

CHIP_ERROR DeferredAttributePersistenceProvider::WriteValue(const ConcreteAttributePath & aPath, const ByteSpan & aValue)
Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,8 @@ - (void)readAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullable)attri
//
callback->AdoptReadClient(std::move(readClient));
callback.release();
IgnoreUnusedVariable(attributePathParamsList.Release());
IgnoreUnusedVariable(eventPathParamsList.Release());
attributePathParamsList.Release();
eventPathParamsList.Release();
return err;
});
std::move(*bridge).DispatchAction(self);
Expand Down
30 changes: 9 additions & 21 deletions src/lib/support/ScopedBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#pragma once

#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>

#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -85,11 +84,10 @@ class ScopedMemoryBufferBase
const void * Ptr() const { return mBuffer; }

/**
* Releases the underlying buffer.
*
* The buffer stops being managed and will not be auto-freed.
* Releases the undelying buffer. Buffer stops being managed and will not be
* auto-freed.
*/
CHECK_RETURN_VALUE void * Release()
void * Release()
{
void * buffer = mBuffer;
mBuffer = nullptr;
Expand Down Expand Up @@ -141,18 +139,13 @@ class ScopedMemoryBuffer : public Impl::ScopedMemoryBufferBase<MemoryManagement>

static_assert(std::is_trivially_destructible<T>::value, "Destructors won't get run");

T * Get() { return static_cast<T *>(Base::Ptr()); }
T & operator[](size_t index) { return Get()[index]; }
inline T * Get() { return static_cast<T *>(Base::Ptr()); }
inline T & operator[](size_t index) { return Get()[index]; }

const T * Get() const { return static_cast<const T *>(Base::Ptr()); }
const T & operator[](size_t index) const { return Get()[index]; }
inline const T * Get() const { return static_cast<const T *>(Base::Ptr()); }
inline const T & operator[](size_t index) const { return Get()[index]; }

/**
* Releases the underlying buffer.
*
* The buffer stops being managed and will not be auto-freed.
*/
CHECK_RETURN_VALUE T * Release() { return static_cast<T *>(Base::Release()); }
inline T * Release() { return static_cast<T *>(Base::Release()); }

ScopedMemoryBuffer & Calloc(size_t elementCount)
{
Expand Down Expand Up @@ -229,12 +222,7 @@ class ScopedMemoryBufferWithSize : public ScopedMemoryBuffer<T>
ScopedMemoryBuffer<T>::Free();
}

/**
* Releases the underlying buffer.
*
* The buffer stops being managed and will not be auto-freed.
*/
CHECK_RETURN_VALUE T * Release()
T * Release()
{
T * buffer = ScopedMemoryBuffer<T>::Release();
mCount = 0;
Expand Down

0 comments on commit 5251d62

Please sign in to comment.