mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Fix heap use after free
This commit is contained in:
parent
4c8aa04b73
commit
487bc0fba3
@ -227,6 +227,10 @@ void LocalServer::cleanup()
|
||||
global_context.reset();
|
||||
}
|
||||
|
||||
/// thread status should be destructed before shared context because it relies on process list.
|
||||
thread_status.reset();
|
||||
shared_context.reset();
|
||||
|
||||
status.reset();
|
||||
|
||||
// Delete the temporary directory if needed.
|
||||
@ -366,12 +370,7 @@ int LocalServer::main(const std::vector<std::string> & /*args*/)
|
||||
try
|
||||
{
|
||||
UseSSL use_ssl;
|
||||
ThreadStatus thread_status;
|
||||
SCOPE_EXIT_SAFE({
|
||||
/// Context should not live longer than thread_status.
|
||||
global_context.reset();
|
||||
shared_context.reset();
|
||||
});
|
||||
thread_status.emplace();
|
||||
|
||||
StackTrace::setShowAddresses(config().getBool("show_addresses_in_stack_traces", true));
|
||||
|
||||
|
@ -176,9 +176,6 @@ protected:
|
||||
bool stderr_is_a_tty = false; /// stderr is a terminal.
|
||||
uint64_t terminal_width = 0;
|
||||
|
||||
ServerConnectionPtr connection;
|
||||
ConnectionParameters connection_parameters;
|
||||
|
||||
String format; /// Query results output format.
|
||||
bool select_into_file = false; /// If writing result INTO OUTFILE. It affects progress rendering.
|
||||
bool select_into_file_and_stdout = false; /// If writing result INTO OUTFILE AND STDOUT. It affects progress rendering.
|
||||
@ -199,6 +196,11 @@ protected:
|
||||
SharedContextHolder shared_context;
|
||||
ContextMutablePtr global_context;
|
||||
|
||||
std::optional<ThreadStatus> thread_status;
|
||||
|
||||
ServerConnectionPtr connection;
|
||||
ConnectionParameters connection_parameters;
|
||||
|
||||
/// Buffer that reads from stdin in batch mode.
|
||||
ReadBufferFromFileDescriptor std_in{STDIN_FILENO};
|
||||
/// Console output.
|
||||
|
@ -31,9 +31,6 @@ LocalConnection::LocalConnection(ContextPtr context_, bool send_progress_, bool
|
||||
/// Authenticate and create a context to execute queries.
|
||||
session.authenticate("default", "", Poco::Net::SocketAddress{});
|
||||
session.makeSessionContext();
|
||||
|
||||
if (!CurrentThread::isInitialized())
|
||||
thread_status.emplace();
|
||||
}
|
||||
|
||||
LocalConnection::~LocalConnection()
|
||||
|
@ -156,7 +156,6 @@ private:
|
||||
String description = "clickhouse-local";
|
||||
|
||||
std::optional<LocalQueryState> state;
|
||||
std::optional<ThreadStatus> thread_status;
|
||||
|
||||
/// Last "server" packet.
|
||||
std::optional<UInt64> next_packet_type;
|
||||
|
@ -143,7 +143,7 @@ namespace ErrorCodes
|
||||
/** Set of known objects (environment), that could be used in query.
|
||||
* Shared (global) part. Order of members (especially, order of destruction) is very important.
|
||||
*/
|
||||
struct ContextSharedPart
|
||||
struct ContextSharedPart : boost::noncopyable
|
||||
{
|
||||
Poco::Logger * log = &Poco::Logger::get("Context");
|
||||
|
||||
@ -314,11 +314,19 @@ struct ContextSharedPart
|
||||
|
||||
~ContextSharedPart()
|
||||
{
|
||||
/// Wait for thread pool for background writes,
|
||||
/// since it may use per-user MemoryTracker which will be destroyed here.
|
||||
try
|
||||
{
|
||||
/// Wait for thread pool for background writes,
|
||||
/// since it may use per-user MemoryTracker which will be destroyed here.
|
||||
IObjectStorage::getThreadPoolWriter().wait();
|
||||
/// Make sure that threadpool is destructed before this->process_list
|
||||
/// because thread_status, which was created for threads inside threadpool,
|
||||
/// relies on it.
|
||||
if (load_marks_threadpool)
|
||||
{
|
||||
load_marks_threadpool->wait();
|
||||
load_marks_threadpool.reset();
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user