summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/FixedArray.h8
-rw-r--r--Tests/AK/TestFixedArray.cpp3
2 files changed, 3 insertions, 8 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;
}
diff --git a/Tests/AK/TestFixedArray.cpp b/Tests/AK/TestFixedArray.cpp
index 1558619f79..872f97767b 100644
--- a/Tests/AK/TestFixedArray.cpp
+++ b/Tests/AK/TestFixedArray.cpp
@@ -23,7 +23,4 @@ TEST_CASE(ints)
EXPECT_EQ(ints[0], 0);
EXPECT_EQ(ints[1], 1);
EXPECT_EQ(ints[2], 2);
-
- ints.clear();
- EXPECT_EQ(ints.size(), 0u);
}