diff options
author | kleines Filmröllchen <malu.bertsch@gmail.com> | 2022-01-12 22:28:43 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-13 11:17:44 +0100 |
commit | 1d144ed6fcc1768a6cce7408bfb633ed7849d847 (patch) | |
tree | dd7d79ac08c97b99eeb82b49a9bd1992d4f46a99 /AK | |
parent | 9bf2d0b71860c03939944c2175956435b60871fa (diff) | |
download | serenity-1d144ed6fcc1768a6cce7408bfb633ed7849d847.zip |
AK: Remove clear() from FixedArray and fixate its allocation guarantees
FixedArray always *almost* had the following allocation guarantees:
There is (possibly) one allocation in the constructor and one (or more)
deallocation(s) in the destructor. No other operation allocates or
deallocates. With this removal of the public clear() method, which
nobody except the test used anyways, those guarantees are now completely
true and furthermore fixated with an explanatory comment.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/FixedArray.h | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/AK/FixedArray.h b/AK/FixedArray.h index e793de8a38..9085399798 100644 --- a/AK/FixedArray.h +++ b/AK/FixedArray.h @@ -14,6 +14,8 @@ namespace AK { +// FixedArray is an Array with a size only known at run-time. +// It guarantees to only allocate when being constructed, and to only deallocate when being destructed. template<typename T> class FixedArray { public: @@ -69,16 +71,12 @@ public: ~FixedArray() { - clear(); - } - - void clear() - { if (!m_elements) return; for (size_t i = 0; i < m_size; ++i) m_elements[i].~T(); kfree_sized(m_elements, sizeof(T) * m_size); + // NOTE: should prevent use-after-free early m_size = 0; m_elements = nullptr; } |