Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter_policy object leak in NodeStore backends #484

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ripple/nodestore/backend/HyperDBFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class HyperDBBackend
Scheduler& m_scheduler;
BatchWriter m_batch;
std::string m_name;
std::unique_ptr <const hyperleveldb::FilterPolicy> m_filter_policy;
std::unique_ptr <hyperleveldb::DB> m_db;

HyperDBBackend (size_t keyBytes, Parameters const& keyValues,
Expand Down Expand Up @@ -69,6 +70,7 @@ class HyperDBBackend
{
options.filter_policy = hyperleveldb::NewBloomFilterPolicy (keyValues ["filter_bits"].getIntValue ());
}
m_filter_policy.reset (options.filter_policy);

if (! keyValues["open_files"].isEmpty ())
{
Expand Down
2 changes: 2 additions & 0 deletions src/ripple/nodestore/backend/LevelDBFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LevelDBBackend
Scheduler& m_scheduler;
BatchWriter m_batch;
std::string m_name;
std::unique_ptr <const leveldb::FilterPolicy> m_filter_policy;
std::unique_ptr <leveldb::DB> m_db;

LevelDBBackend (int keyBytes, Parameters const& keyValues,
Expand Down Expand Up @@ -69,6 +70,7 @@ class LevelDBBackend
{
options.filter_policy = leveldb::NewBloomFilterPolicy (keyValues["filter_bits"].getIntValue());
}
m_filter_policy.reset (options.filter_policy);

if (! keyValues["open_files"].isEmpty())
{
Expand Down
2 changes: 2 additions & 0 deletions src/ripple/nodestore/backend/RocksDBFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class RocksDBBackend
Scheduler& m_scheduler;
BatchWriter m_batch;
std::string m_name;
std::unique_ptr <const rocksdb::FilterPolicy> m_filter_policy;
std::unique_ptr <rocksdb::DB> m_db;

RocksDBBackend (int keyBytes, Parameters const& keyValues,
Expand Down Expand Up @@ -120,6 +121,7 @@ class RocksDBBackend
{
options.filter_policy = rocksdb::NewBloomFilterPolicy (keyValues["filter_bits"].getIntValue());
}
m_filter_policy.reset (options.filter_policy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a style comment, it's better form to immediately put the raw pointer into the smart pointer, and then use it after that.

The reason is that you want to minimize the gap between "creating the pointer" and "making sure it can't be leaked".

In this case, assigning options.filter_policy isn't going to throw an exception so it's academic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Tom


if (! keyValues["open_files"].isEmpty())
{
Expand Down