diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-05-13 01:41:26 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-13 16:21:53 +0200 |
commit | c8758d4faafd3556da636dd973b09256b82bd5db (patch) | |
tree | 4535e998da4a6b4801942a5aa7ccd9ede1c63817 /Kernel/KBuffer.h | |
parent | 2e34714ba139a341f957b69c30a7ca106f460794 (diff) | |
download | serenity-c8758d4faafd3556da636dd973b09256b82bd5db.zip |
Kernel: Make KBuffer::try_create_with* APIs OOM safe
Diffstat (limited to 'Kernel/KBuffer.h')
-rw-r--r-- | Kernel/KBuffer.h | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Kernel/KBuffer.h b/Kernel/KBuffer.h index fc76fee6aa..f49dd51d88 100644 --- a/Kernel/KBuffer.h +++ b/Kernel/KBuffer.h @@ -32,7 +32,7 @@ public: auto region = MM.allocate_kernel_region(page_round_up(size), name, access, strategy); if (!region) return nullptr; - return adopt_ref(*new KBufferImpl(region.release_nonnull(), size, strategy)); + return adopt_ref_if_nonnull(new KBufferImpl(region.release_nonnull(), size, strategy)); } static RefPtr<KBufferImpl> try_create_with_bytes(ReadonlyBytes bytes, Region::Access access, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) @@ -41,7 +41,8 @@ public: if (!region) return nullptr; memcpy(region->vaddr().as_ptr(), bytes.data(), bytes.size()); - return adopt_ref(*new KBufferImpl(region.release_nonnull(), bytes.size(), strategy)); + + return adopt_ref_if_nonnull(new KBufferImpl(region.release_nonnull(), bytes.size(), strategy)); } static RefPtr<KBufferImpl> create_with_size(size_t size, Region::Access access, const char* name, AllocationStrategy strategy = AllocationStrategy::Reserve) |