mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
Kernel: Make KBuffer::try_create_with* APIs OOM safe
This commit is contained in:
parent
2e34714ba1
commit
c8758d4faa
1 changed files with 3 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue