From d1d2d0b02fb982e0bbb0a6ba32bc90b25fff2b53 Mon Sep 17 00:00:00 2001 From: halgari Date: Wed, 10 Apr 2024 15:56:22 -0600 Subject: [PATCH] Fix crash during dispose of RocksDB.Backend when it's not initialized before being disposed --- .../RocksDbBackend/Backend.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NexusMods.MnemonicDB.Storage/RocksDbBackend/Backend.cs b/src/NexusMods.MnemonicDB.Storage/RocksDbBackend/Backend.cs index f3f1b44d..b68a3cf2 100644 --- a/src/NexusMods.MnemonicDB.Storage/RocksDbBackend/Backend.cs +++ b/src/NexusMods.MnemonicDB.Storage/RocksDbBackend/Backend.cs @@ -14,11 +14,11 @@ public class Backend(AttributeRegistry registry) : IStoreBackend private readonly ColumnFamilies _columnFamilies = new(); private readonly Dictionary _indexes = new(); private readonly Dictionary _stores = new(); - private RocksDb _db = null!; + private RocksDb? _db = null!; public IWriteBatch CreateBatch() { - return new Batch(_db); + return new Batch(_db!); } public void DeclareIndex(IndexType name) @@ -61,12 +61,12 @@ public void Init(AbsolutePath location) public void Dispose() { - _db.Dispose(); + _db?.Dispose(); } private class Snapshot(Backend backend, AttributeRegistry registry) : ISnapshot { - private readonly RocksDbSharp.Snapshot _snapshot = backend._db.CreateSnapshot(); + private readonly RocksDbSharp.Snapshot _snapshot = backend._db!.CreateSnapshot(); public IEnumerable Datoms(IndexType type, ReadOnlySpan a, ReadOnlySpan b) { @@ -92,7 +92,7 @@ public IEnumerable Datoms(IndexType type, ReadOnlySpan a, ReadOnlyS private IEnumerable DatomsInner(IndexType type, ReadOptions options, bool reverse) { - using var iterator = backend._db.NewIterator(backend._stores[type].Handle, options); + using var iterator = backend._db!.NewIterator(backend._stores[type].Handle, options); if (reverse) iterator.SeekToLast(); else