Skip to content

Commit 1ae2514

Browse files
author
Nick White
committed
Fix Ref-Counting Error in Versions
Fixes #136. References to a DBImpl's VersionSet can be left in the LRUCache, so delete the cache before the VersionSet
1 parent e353fbc commit 1ae2514

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

db/db_impl.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,15 @@ DBImpl::~DBImpl() {
158158
env_->UnlockFile(db_lock_);
159159
}
160160

161+
// delete the cache first in case it has outstanding references
162+
delete table_cache_;
163+
161164
delete versions_;
162165
if (mem_ != NULL) mem_->Unref();
163166
if (imm_ != NULL) imm_->Unref();
164167
delete tmp_batch_;
165168
delete log_;
166169
delete logfile_;
167-
delete table_cache_;
168170

169171
if (owns_info_log_) {
170172
delete options_.info_log;
@@ -1047,15 +1049,16 @@ Iterator* DBImpl::NewInternalIterator(const ReadOptions& options,
10471049
list.push_back(imm_->NewIterator());
10481050
imm_->Ref();
10491051
}
1050-
versions_->current()->AddIterators(options, &list);
1052+
Version* current = versions_->current();
1053+
current->AddIterators(options, &list);
10511054
Iterator* internal_iter =
10521055
NewMergingIterator(&internal_comparator_, &list[0], list.size());
1053-
versions_->current()->Ref();
1056+
current->Ref();
10541057

10551058
cleanup->mu = &mutex_;
10561059
cleanup->mem = mem_;
10571060
cleanup->imm = imm_;
1058-
cleanup->version = versions_->current();
1061+
cleanup->version = current;
10591062
internal_iter->RegisterCleanup(CleanupIteratorState, cleanup, NULL);
10601063

10611064
*seed = ++seed_;
@@ -1407,8 +1410,8 @@ void DBImpl::GetApproximateSizes(
14071410
Version* v;
14081411
{
14091412
MutexLock l(&mutex_);
1410-
versions_->current()->Ref();
14111413
v = versions_->current();
1414+
v->Ref();
14121415
}
14131416

14141417
for (int i = 0; i < n; i++) {

0 commit comments

Comments
 (0)