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.
This commit is contained in:
Brian Gianforcaro 2021-05-12 23:01:55 -07:00 committed by Andreas Kling
parent 5dc5f31f76
commit fb40da0429

View file

@ -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();
}