Skip to content

Commit

Permalink
fix: Close uninitialized boxes (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
themisir committed Mar 11, 2022
1 parent 7b5f9fa commit c328ced
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hive/lib/src/hive_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
var completer = Completer();
_openingBoxes[name] = completer.future;

BoxBaseImpl<E>? newBox;
try {
StorageBackend backend;
if (bytes != null) {
Expand All @@ -100,7 +101,6 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
await _manager.open(name, path ?? homePath, recovery, cipher);
}

BoxBaseImpl<E> newBox;
if (lazy) {
newBox = LazyBoxImpl<E>(this, name, comparator, compaction, backend);
} else {
Expand All @@ -113,6 +113,7 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
completer.complete();
return newBox;
} catch (error, stackTrace) {
newBox?.close();
completer.completeError(error, stackTrace);
rethrow;
} finally {
Expand Down

0 comments on commit c328ced

Please sign in to comment.