Skip to content

Commit

Permalink
Merge pull request #5871 from yandex/fix-clickhouse-copier-heap-use-a…
Browse files Browse the repository at this point in the history
…fter-free

Fix heap-use-after-free in ClusterCopier

(cherry picked from commit bc1e9df)
  • Loading branch information
KochetovNicolai authored and abyss7 committed Jul 11, 2019
1 parent 5cafd6c commit 06085be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dbms/programs/copier/ClusterCopier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,10 @@ void ClusterCopierApp::mainImpl()

copier->init();
copier->process(ConnectionTimeouts::getTCPTimeoutsWithoutFailover(context->getSettingsRef()));

/// Reset ZooKeeper before removing ClusterCopier.
/// Otherwise zookeeper watch can call callback which use already removed ClusterCopier object.
context->resetZooKeeper();
}


Expand Down
6 changes: 6 additions & 0 deletions dbms/src/Interpreters/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,12 @@ zkutil::ZooKeeperPtr Context::getZooKeeper() const
return shared->zookeeper;
}

void Context::resetZooKeeper() const
{
std::lock_guard lock(shared->zookeeper_mutex);
shared->zookeeper.reset();
}

bool Context::hasZooKeeper() const
{
return getConfigRef().has("zookeeper");
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Interpreters/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ class Context
std::shared_ptr<zkutil::ZooKeeper> getZooKeeper() const;
/// Has ready or expired ZooKeeper
bool hasZooKeeper() const;
/// Reset current zookeeper session. Do not create a new one.
void resetZooKeeper() const;

/// Create a cache of uncompressed blocks of specified size. This can be done only once.
void setUncompressedCache(size_t max_size_in_bytes);
Expand Down

0 comments on commit 06085be

Please sign in to comment.