diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-05-12 23:01:55 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-13 16:21:53 +0200 |
commit | fb40da0429e1dcd306e3216b5c73cfd199194317 (patch) | |
tree | 5387bd80d7273deb373de759c0164633525811e5 /Kernel/FileSystem/Ext2FileSystem.cpp | |
parent | 5dc5f31f76a734c1ad98b82b8081c027f18ca6a7 (diff) | |
download | serenity-fb40da0429e1dcd306e3216b5c73cfd199194317.zip |
Kernel: Replace make<T>() with adopt_own_if_nonnull() in Ext2FileSystem
The make<T> factory function allocates internally and immediately
dereferences the pointer, and always returns a NonnullOwnPtr<T> making
it impossible to propagate an error on OOM.
Diffstat (limited to 'Kernel/FileSystem/Ext2FileSystem.cpp')
-rw-r--r-- | Kernel/FileSystem/Ext2FileSystem.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 30e59c2806..d36b710401 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -1495,7 +1495,10 @@ KResultOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_bloc dbgln("Ext2FS: Failed to load bitmap block {}", bitmap_block_index); return result; } - if (!m_cached_bitmaps.try_append(make<CachedBitmap>(bitmap_block_index, move(block)))) + auto new_bitmap = adopt_own_if_nonnull(new CachedBitmap(bitmap_block_index, move(block))); + if (!new_bitmap) + return ENOMEM; + if (!m_cached_bitmaps.try_append(move(new_bitmap))) return ENOMEM; return m_cached_bitmaps.last(); } |