From fb40da0429e1dcd306e3216b5c73cfd199194317 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Wed, 12 May 2021 23:01:55 -0700 Subject: [PATCH] Kernel: Replace make() with adopt_own_if_nonnull() in Ext2FileSystem The make factory function allocates internally and immediately dereferences the pointer, and always returns a NonnullOwnPtr making it impossible to propagate an error on OOM. --- Kernel/FileSystem/Ext2FileSystem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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::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(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(); }