Fixed use after free on p2pool shutdown

This commit is contained in:
SChernykh
2021-08-27 10:13:33 +02:00
parent 715c0d4e14
commit 776b1f561c
3 changed files with 11 additions and 5 deletions
+9 -4
View File
@@ -95,9 +95,6 @@ p2pool::p2pool(int argc, char* argv[])
p2pool::~p2pool()
{
uv_close(reinterpret_cast<uv_handle_t*>(&m_submitBlockAsync), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&m_blockTemplateAsync), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&m_stopAsync), nullptr);
uv_rwlock_destroy(&m_mainchainLock);
uv_mutex_destroy(&m_submitBlockDataLock);
@@ -290,6 +287,15 @@ void p2pool::submit_block_async(const std::vector<uint8_t>& blob)
}
}
void p2pool::on_stop(uv_async_t* async)
{
p2pool* pool = reinterpret_cast<p2pool*>(async->data);
uv_close(reinterpret_cast<uv_handle_t*>(&pool->m_submitBlockAsync), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&pool->m_blockTemplateAsync), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&pool->m_stopAsync), nullptr);
uv_stop(uv_default_loop());
}
void p2pool::submit_block() const
{
SubmitBlockData submit_data;
@@ -733,7 +739,6 @@ static bool init_signals(p2pool* pool)
void p2pool::stop()
{
uv_stop(uv_default_loop());
uv_async_send(&m_stopAsync);
}