mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-02 04:20:28 +00:00
AK: Prevent accidental misuse of BumpAllocator
In particular, we implicitly required that the caller initializes the returned instances themselves (solved by making UniformBumpAllocator::allocate call the constructor), and BumpAllocator itself cannot handle classes that are not trivially deconstructible (solved by deleting the method). Co-authored-by: Ali Mohammad Pur <ali.mpfard@gmail.com>
This commit is contained in:
parent
5d865d574a
commit
50698a0db4
Notes:
sideshowbarker
2024-07-18 01:58:11 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/50698a0db46 Pull-request: https://github.com/SerenityOS/serenity/pull/10579 Reviewed-by: https://github.com/alimpfard ✅
2 changed files with 10 additions and 13 deletions
|
@ -51,12 +51,6 @@ public:
|
|||
return (void*)aligned_ptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* allocate()
|
||||
{
|
||||
return (T*)allocate(sizeof(T), alignof(T));
|
||||
}
|
||||
|
||||
void deallocate_all()
|
||||
{
|
||||
if (!m_head_chunk)
|
||||
|
@ -160,9 +154,13 @@ public:
|
|||
destroy_all();
|
||||
}
|
||||
|
||||
T* allocate()
|
||||
template<typename... Args>
|
||||
T* allocate(Args&&... args)
|
||||
{
|
||||
return Allocator::template allocate<T>();
|
||||
auto ptr = (T*)Allocator::allocate(sizeof(T), alignof(T));
|
||||
if (!ptr)
|
||||
return nullptr;
|
||||
return new (ptr) T { forward<Args>(args)... };
|
||||
}
|
||||
|
||||
void deallocate_all()
|
||||
|
|
|
@ -333,13 +333,12 @@ public:
|
|||
|
||||
ALWAYS_INLINE void append(T value)
|
||||
{
|
||||
auto new_node = m_allocator.allocate();
|
||||
VERIFY(new_node);
|
||||
auto node_ptr = new (new_node) Node { move(value), nullptr, nullptr };
|
||||
auto node_ptr = m_allocator.allocate(move(value));
|
||||
VERIFY(node_ptr);
|
||||
|
||||
if (!m_first) {
|
||||
m_first = new_node;
|
||||
m_last = new_node;
|
||||
m_first = node_ptr;
|
||||
m_last = node_ptr;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue