|
25 | 25 | #pragma once
|
26 | 26 |
|
27 | 27 | #include <lib/support/CHIPMem.h>
|
| 28 | +#include <lib/support/CodeUtils.h> |
28 | 29 |
|
29 | 30 | #include <type_traits>
|
30 | 31 | #include <utility>
|
@@ -84,10 +85,11 @@ class ScopedMemoryBufferBase
|
84 | 85 | const void * Ptr() const { return mBuffer; }
|
85 | 86 |
|
86 | 87 | /**
|
87 |
| - * Releases the undelying buffer. Buffer stops being managed and will not be |
88 |
| - * auto-freed. |
| 88 | + * Releases the underlying buffer. |
| 89 | + * |
| 90 | + * The buffer stops being managed and will not be auto-freed. |
89 | 91 | */
|
90 |
| - void * Release() |
| 92 | + CHECK_RETURN_VALUE void * Release() |
91 | 93 | {
|
92 | 94 | void * buffer = mBuffer;
|
93 | 95 | mBuffer = nullptr;
|
@@ -139,13 +141,18 @@ class ScopedMemoryBuffer : public Impl::ScopedMemoryBufferBase<MemoryManagement>
|
139 | 141 |
|
140 | 142 | static_assert(std::is_trivially_destructible<T>::value, "Destructors won't get run");
|
141 | 143 |
|
142 |
| - inline T * Get() { return static_cast<T *>(Base::Ptr()); } |
143 |
| - inline T & operator[](size_t index) { return Get()[index]; } |
| 144 | + T * Get() { return static_cast<T *>(Base::Ptr()); } |
| 145 | + T & operator[](size_t index) { return Get()[index]; } |
144 | 146 |
|
145 |
| - inline const T * Get() const { return static_cast<const T *>(Base::Ptr()); } |
146 |
| - inline const T & operator[](size_t index) const { return Get()[index]; } |
| 147 | + const T * Get() const { return static_cast<const T *>(Base::Ptr()); } |
| 148 | + const T & operator[](size_t index) const { return Get()[index]; } |
147 | 149 |
|
148 |
| - inline T * Release() { return static_cast<T *>(Base::Release()); } |
| 150 | + /** |
| 151 | + * Releases the underlying buffer. |
| 152 | + * |
| 153 | + * The buffer stops being managed and will not be auto-freed. |
| 154 | + */ |
| 155 | + CHECK_RETURN_VALUE T * Release() { return static_cast<T *>(Base::Release()); } |
149 | 156 |
|
150 | 157 | ScopedMemoryBuffer & Calloc(size_t elementCount)
|
151 | 158 | {
|
@@ -222,7 +229,12 @@ class ScopedMemoryBufferWithSize : public ScopedMemoryBuffer<T>
|
222 | 229 | ScopedMemoryBuffer<T>::Free();
|
223 | 230 | }
|
224 | 231 |
|
225 |
| - T * Release() |
| 232 | + /** |
| 233 | + * Releases the underlying buffer. |
| 234 | + * |
| 235 | + * The buffer stops being managed and will not be auto-freed. |
| 236 | + */ |
| 237 | + CHECK_RETURN_VALUE T * Release() |
226 | 238 | {
|
227 | 239 | T * buffer = ScopedMemoryBuffer<T>::Release();
|
228 | 240 | mCount = 0;
|
|
0 commit comments