From 8e29abd9060def15a4f6eed08f11fdb0492aa0ba Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 29 Aug 2021 00:13:53 +0200 Subject: [PATCH] Small fixes --- src/memory_leak_debug.cpp | 21 ++++++++++++++------- src/side_chain.cpp | 2 +- src/tcp_server.h | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/memory_leak_debug.cpp b/src/memory_leak_debug.cpp index 75db321..13d2fbc 100644 --- a/src/memory_leak_debug.cpp +++ b/src/memory_leak_debug.cpp @@ -117,19 +117,26 @@ FORCEINLINE static void remove_allocation(void* p) return; } } - if (!found) { - // Someone tried to deallocate a pointer that wasn't allocated before - __debugbreak(); + + // Someone tried to deallocate a pointer that wasn't allocated before + __debugbreak(); +} + +FORCEINLINE static void* allocate_noexcept(size_t n) noexcept +{ + void* p = malloc(n + sizeof(TrackedAllocation)); + if (p) { + add_alocation(p, n); } + return p; } FORCEINLINE static void* allocate(size_t n) { - void* p = malloc(n + sizeof(TrackedAllocation)); + void* p = allocate_noexcept(n); if (!p) { throw std::bad_alloc(); } - add_alocation(p, n); return p; } @@ -202,8 +209,8 @@ void memory_tracking_stop() NOINLINE void* operator new(size_t n) { return p2pool::allocate(n); } NOINLINE void* operator new[](size_t n) { return p2pool::allocate(n); } -NOINLINE void* operator new(size_t n, const std::nothrow_t&) noexcept { return p2pool::allocate(n); } -NOINLINE void* operator new[](size_t n, const std::nothrow_t&) noexcept { return p2pool::allocate(n); } +NOINLINE void* operator new(size_t n, const std::nothrow_t&) noexcept { return p2pool::allocate_noexcept(n); } +NOINLINE void* operator new[](size_t n, const std::nothrow_t&) noexcept { return p2pool::allocate_noexcept(n); } NOINLINE void operator delete(void* p) noexcept { p2pool::deallocate(p); } NOINLINE void operator delete[](void* p) noexcept { p2pool::deallocate(p); } NOINLINE void operator delete(void* p, size_t) noexcept { p2pool::deallocate(p); } diff --git a/src/side_chain.cpp b/src/side_chain.cpp index c55a014..c6b5517 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -657,7 +657,7 @@ void SideChain::print_status() "\nYour hashrate (est) = " << log::Hashrate(hashrate_est) << "\nPPLNS window = " << total_blocks_in_window << " blocks (+" << total_uncles_in_window << " uncles, " << total_orphans << " orphans)" "\nYour shares = " << our_blocks_in_window << " blocks (+" << our_uncles_in_window << " uncles, " << our_orphans << " orphans)" - "\nNext payout = " << log::XMRAmount(next_payout) + "\nNext payout (est) = " << log::XMRAmount(next_payout) ); } diff --git a/src/tcp_server.h b/src/tcp_server.h index 80e3aeb..71aece2 100644 --- a/src/tcp_server.h +++ b/src/tcp_server.h @@ -30,7 +30,7 @@ public: struct Client; typedef Client* (*allocate_client_callback)(); - TCPServer(allocate_client_callback allocate_new_client); + explicit TCPServer(allocate_client_callback allocate_new_client); virtual ~TCPServer(); template