mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-31 15:59:27 +00:00
Fixed memory leaks
This commit is contained in:
parent
8b681d6efb
commit
8af9e9b27d
5 changed files with 12 additions and 4 deletions
|
@ -338,6 +338,10 @@ void CurlContext::on_close(uv_handle_t* h)
|
||||||
|
|
||||||
void Call(const std::string& address, int port, const std::string& req, const std::string& auth, CallbackBase* cb, CallbackBase* close_cb, uv_loop_t* loop)
|
void Call(const std::string& address, int port, const std::string& req, const std::string& auth, CallbackBase* cb, CallbackBase* close_cb, uv_loop_t* loop)
|
||||||
{
|
{
|
||||||
|
if (!loop) {
|
||||||
|
loop = uv_default_loop();
|
||||||
|
}
|
||||||
|
|
||||||
CallOnLoop(loop,
|
CallOnLoop(loop,
|
||||||
[=]()
|
[=]()
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ private:
|
||||||
void Call(const std::string& address, int port, const std::string& req, const std::string& auth, CallbackBase* cb, CallbackBase* close_cb, uv_loop_t* loop);
|
void Call(const std::string& address, int port, const std::string& req, const std::string& auth, CallbackBase* cb, CallbackBase* close_cb, uv_loop_t* loop);
|
||||||
|
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
FORCEINLINE void call(const std::string& address, int port, const std::string& req, const std::string& auth, T&& cb, U&& close_cb, uv_loop_t* loop = uv_default_loop_checked())
|
FORCEINLINE void call(const std::string& address, int port, const std::string& req, const std::string& auth, T&& cb, U&& close_cb, uv_loop_t* loop = nullptr)
|
||||||
{
|
{
|
||||||
Call(address, port, req, auth, new Callback<T>(std::move(cb)), new Callback<U>(std::move(close_cb)), loop);
|
Call(address, port, req, auth, new Callback<T>(std::move(cb)), new Callback<U>(std::move(close_cb)), loop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,10 @@ P2PServer::~P2PServer()
|
||||||
|
|
||||||
delete m_block;
|
delete m_block;
|
||||||
delete m_cache;
|
delete m_cache;
|
||||||
|
|
||||||
|
for (const Broadcast* data : m_broadcastQueue) {
|
||||||
|
delete data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PServer::add_cached_block(const PoolBlock& block)
|
void P2PServer::add_cached_block(const PoolBlock& block)
|
||||||
|
@ -785,7 +789,7 @@ void P2PServer::on_broadcast()
|
||||||
|
|
||||||
ON_SCOPE_LEAVE([&broadcast_queue]()
|
ON_SCOPE_LEAVE([&broadcast_queue]()
|
||||||
{
|
{
|
||||||
for (Broadcast* data : broadcast_queue) {
|
for (const Broadcast* data : broadcast_queue) {
|
||||||
delete data;
|
delete data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -473,7 +473,7 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::shutdown_tcp()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOGWARN(1, "timed out while waiting for event loop to stop");
|
LOGWARN(1, "timed out while waiting for event loop to stop");
|
||||||
uv_async_init(&m_loop, &asy, nullptr);
|
uv_async_init(&m_loop, &asy, [](uv_async_t* h) { uv_close(reinterpret_cast<uv_handle_t*>(h), nullptr); });
|
||||||
uv_stop(&m_loop);
|
uv_stop(&m_loop);
|
||||||
uv_async_send(&asy);
|
uv_async_send(&asy);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -139,7 +139,7 @@ UV_LoopUserData* GetLoopUserData(uv_loop_t* loop, bool create = true);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void CallOnLoop(uv_loop_t* loop, T&& callback)
|
void CallOnLoop(uv_loop_t* loop, T&& callback)
|
||||||
{
|
{
|
||||||
UV_LoopUserData* data = GetLoopUserData(loop);
|
UV_LoopUserData* data = GetLoopUserData(loop, false);
|
||||||
|
|
||||||
UV_LoopCallbackBase* cb = new UV_LoopCallback<T>(std::move(callback));
|
UV_LoopCallbackBase* cb = new UV_LoopCallback<T>(std::move(callback));
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue