P2PServer: fixed m_timer leak

pull/71/head
SChernykh 3 years ago
parent 352ad81a0a
commit 04d18cdf1d

@ -122,7 +122,7 @@ FORCEINLINE static void remove_allocation(void* p)
FORCEINLINE static void* allocate_noexcept(size_t n) noexcept FORCEINLINE static void* allocate_noexcept(size_t n) noexcept
{ {
void* p = malloc(n + sizeof(TrackedAllocation)); void* p = malloc(n);
if (p) { if (p) {
add_alocation(p, n); add_alocation(p, n);
} }
@ -144,12 +144,33 @@ FORCEINLINE static void deallocate(void* p)
free(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 } // p2pool
void memory_tracking_start() void memory_tracking_start()
{ {
using namespace p2pool; using namespace p2pool;
uv_replace_allocator(allocate_noexcept, uv_realloc_hook, uv_calloc_hook, deallocate);
uv_mutex_init_checked(&allocation_lock); uv_mutex_init_checked(&allocation_lock);
track_memory = true; track_memory = true;
} }

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

Loading…
Cancel
Save