From 8ac85b68acb8082492c7bff5e3e99efcbe446a14 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Thu, 5 Apr 2018 15:51:10 -0400 Subject: [PATCH] Fix DB memory leak in transaction containers Transactions are stored in the DB via a multi-index container for purposes of deduplication checks. The index based on expiry is ordered_unique which means items will be sorted ascending for that index. So when pruning old transactions from this container we need to be removing from the start of the index as that's where the oldest transactions will be. Issue #2153 --- libraries/chain/chain_controller.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/chain/chain_controller.cpp b/libraries/chain/chain_controller.cpp index 5a916decd..80d8870fd 100644 --- a/libraries/chain/chain_controller.cpp +++ b/libraries/chain/chain_controller.cpp @@ -1885,15 +1885,16 @@ void chain_controller::clear_expired_transactions() //transactions must have expired by at least two forking windows in order to be removed. auto& transaction_idx = _db.get_mutable_index(); const auto& dedupe_index = transaction_idx.indices().get(); - while( (!dedupe_index.empty()) && (head_block_time() > fc::time_point(dedupe_index.rbegin()->expiration) ) ) - transaction_idx.remove(*dedupe_index.rbegin()); + while( (!dedupe_index.empty()) && (head_block_time() > fc::time_point(dedupe_index.begin()->expiration) ) ) { + transaction_idx.remove(*dedupe_index.begin()); + } //Look for expired transactions in the pending generated list, and remove them. //transactions must have expired by at least two forking windows in order to be removed. auto& generated_transaction_idx = _db.get_mutable_index(); const auto& generated_index = generated_transaction_idx.indices().get(); - while( (!generated_index.empty()) && (head_block_time() > generated_index.rbegin()->expiration) ) { - _destroy_generated_transaction(*generated_index.rbegin()); + while( (!generated_index.empty()) && (head_block_time() > generated_index.begin()->expiration) ) { + _destroy_generated_transaction(*generated_index.begin()); } } FC_CAPTURE_AND_RETHROW() } -- GitLab