summaryrefslogtreecommitdiff
path: root/Kernel/KBufferBuilder.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-07 15:54:23 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-07 15:54:23 +0200
commit300402cc142aaa4e481801146b47b1d0f72c0647 (patch)
tree235fc407db0614c3c1b072f6fabed04641f60b5e /Kernel/KBufferBuilder.cpp
parentbe613b9ef6ceea86aa511d4f411c8638b52e9d22 (diff)
downloadserenity-300402cc142aaa4e481801146b47b1d0f72c0647.zip
Kernel: Make it possible for KBufferBuilder creation to fail
This patch adds KBufferBuilder::try_create() and treats it like anything else that can fail. And so, failure to allocate the initial internal buffer of the builder will now propagate an ENOMEM to the caller. :^)
Diffstat (limited to 'Kernel/KBufferBuilder.cpp')
-rw-r--r--Kernel/KBufferBuilder.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/Kernel/KBufferBuilder.cpp b/Kernel/KBufferBuilder.cpp
index f7340c7d6d..a484888263 100644
--- a/Kernel/KBufferBuilder.cpp
+++ b/Kernel/KBufferBuilder.cpp
@@ -46,8 +46,14 @@ OwnPtr<KBuffer> KBufferBuilder::build()
return move(m_buffer);
}
-KBufferBuilder::KBufferBuilder()
- : m_buffer(KBuffer::try_create_with_size(4 * MiB, Memory::Region::Access::ReadWrite).release_value())
+KResultOr<KBufferBuilder> KBufferBuilder::try_create()
+{
+ auto buffer = TRY(KBuffer::try_create_with_size(4 * MiB, Memory::Region::Access::ReadWrite));
+ return KBufferBuilder { move(buffer) };
+}
+
+KBufferBuilder::KBufferBuilder(NonnullOwnPtr<KBuffer> buffer)
+ : m_buffer(move(buffer))
{
}