Skip to content

Commit

Permalink
Fix crash during dispose of RocksDB.Backend when it's not initialized…
Browse files Browse the repository at this point in the history
… before being disposed
  • Loading branch information
halgari committed Apr 10, 2024
1 parent 21115f8 commit d1d2d0b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/NexusMods.MnemonicDB.Storage/RocksDbBackend/Backend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class Backend(AttributeRegistry registry) : IStoreBackend
private readonly ColumnFamilies _columnFamilies = new();
private readonly Dictionary<IndexType, IRocksDbIndex> _indexes = new();
private readonly Dictionary<IndexType, IndexStore> _stores = new();
private RocksDb _db = null!;
private RocksDb? _db = null!;

public IWriteBatch CreateBatch()
{
return new Batch(_db);
return new Batch(_db!);
}

public void DeclareIndex<TComparator>(IndexType name)
Expand Down Expand Up @@ -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<Datom> Datoms(IndexType type, ReadOnlySpan<byte> a, ReadOnlySpan<byte> b)
{
Expand All @@ -92,7 +92,7 @@ public IEnumerable<Datom> Datoms(IndexType type, ReadOnlySpan<byte> a, ReadOnlyS

private IEnumerable<Datom> 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
Expand Down

0 comments on commit d1d2d0b

Please sign in to comment.