P2PServer: fixed m_timer leak

This commit is contained in:
SChernykh 2021-10-21 19:10:11 +02:00
parent 352ad81a0a
commit 04d18cdf1d
2 changed files with 23 additions and 1 deletions

View file

@ -122,7 +122,7 @@ FORCEINLINE static void remove_allocation(void* p)
FORCEINLINE static void* allocate_noexcept(size_t n) noexcept
{
void* p = malloc(n + sizeof(TrackedAllocation));
void* p = malloc(n);
if (p) {
add_alocation(p, n);
}
@ -144,12 +144,33 @@ FORCEINLINE static void deallocate(void* p)
free(p);
}
static void* uv_realloc_hook(void* ptr, size_t size)
{
remove_allocation(ptr);
void* p = realloc(ptr, size);
if (p) {
add_alocation(p, size);
}
return p;
}
static void* uv_calloc_hook(size_t count, size_t size)
{
void* p = calloc(count, size);
if (p) {
add_alocation(p, size);
}
return p;
}
} // p2pool
void memory_tracking_start()
{
using namespace p2pool;
uv_replace_allocator(allocate_noexcept, uv_realloc_hook, uv_calloc_hook, deallocate);
uv_mutex_init_checked(&allocation_lock);
track_memory = true;
}

View file

@ -94,6 +94,7 @@ P2PServer::P2PServer(p2pool* pool)
P2PServer::~P2PServer()
{
uv_timer_stop(&m_timer);
uv_close(reinterpret_cast<uv_handle_t*>(&m_timer), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&m_broadcastAsync), nullptr);
shutdown_tcp();