1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:47:37 +00:00

LibWasm: Make MemoryInstance allocation fail if initial growth fails

...instead of silently ignoring the failure in the constructor.
This commit is contained in:
Ali Mohammad Pur 2022-02-15 03:05:49 +03:30 committed by Ali Mohammad Pur
parent 117ca843bd
commit 4f2d898a51
2 changed files with 17 additions and 4 deletions

View file

@ -331,10 +331,14 @@ private:
class MemoryInstance {
public:
explicit MemoryInstance(MemoryType const& type)
: m_type(type)
static ErrorOr<MemoryInstance> create(MemoryType const& type)
{
grow(m_type.limits().min() * Constants::page_size);
MemoryInstance instance { type };
if (!instance.grow(type.limits().min() * Constants::page_size))
return Error::from_string_literal("Failed to grow to requested size");
return { move(instance) };
}
auto& type() const { return m_type; }
@ -364,6 +368,11 @@ public:
}
private:
explicit MemoryInstance(MemoryType const& type)
: m_type(type)
{
}
MemoryType const& m_type;
size_t m_size { 0 };
ByteBuffer m_data;