Fix Transaction memory leak

Summary:
- Make sure we clean up recovered_transactions_ on DBImpl destructor
- delete leaked txns and env in TransactionTest

Test Plan: Run transaction_test under valgrind

Reviewers: sdong, andrewkr, yhchiang, horuff

Reviewed By: horuff

Subscribers: andrewkr, dhruba

Differential Revision: https://reviews.facebook.net/D58263
This commit is contained in:
Islam AbdelRahman 2016-05-16 16:32:55 -07:00
parent a08c8c851a
commit f6aedb62c0
2 changed files with 10 additions and 0 deletions

View File

@ -460,6 +460,10 @@ DBImpl::~DBImpl() {
// so the cache can be safely destroyed.
table_cache_->EraseUnRefEntries();
for (auto& txn_entry : recovered_transactions_) {
delete txn_entry.second;
}
// versions need to be destroyed before table_cache since it can hold
// references to table_cache.
versions_.reset();

View File

@ -57,6 +57,7 @@ class TransactionTest : public testing::Test {
~TransactionTest() {
delete db;
DestroyDB(dbname, options);
delete env_;
}
Status ReOpenNoDelete() {
@ -442,6 +443,8 @@ TEST_F(TransactionTest, TwoPhaseRollbackTest) {
// try rollback again
s = txn->Rollback();
ASSERT_EQ(s, Status::InvalidArgument());
delete txn;
}
TEST_F(TransactionTest, PersistentTwoPhaseTransactionTest) {
@ -495,6 +498,7 @@ TEST_F(TransactionTest, PersistentTwoPhaseTransactionTest) {
s = db->Get(read_options, Slice("foo"), &value);
ASSERT_TRUE(s.IsNotFound());
delete txn;
// kill and reopen
s = ReOpenNoDelete();
ASSERT_OK(s);
@ -735,6 +739,8 @@ TEST_F(TransactionTest, TwoPhaseDoubleRecoveryTest) {
s = txn->Commit();
ASSERT_OK(s);
delete txn;
// kill and reopen
env_->SetFilesystemActive(false);
ReOpenNoDelete();