CI: added sync test with memory leak detection

This commit is contained in:
SChernykh
2023-07-19 13:13:00 +02:00
parent 75cc82ae0c
commit 0f88640575
7 changed files with 68 additions and 12 deletions

View File

@@ -18,11 +18,12 @@
#include "common.h"
// Simple memory leak detector for Windows users, works best in RelWithDebInfo configuration.
#if defined(_WIN32) && 0
#if defined(_WIN32) && defined(DEV_TRACK_MEMORY)
#include "uv_util.h"
#include <atomic>
#include <type_traits>
#include <iostream>
#include <DbgHelp.h>
@@ -87,7 +88,7 @@ uint32_t num_allocations = 0;
uint64_t total_allocated = 0;
uint32_t cur_allocation_index = 1;
void show_top_10()
void show_top_10_allocations()
{
TrackedAllocation* buf = reinterpret_cast<TrackedAllocation*>(VirtualAlloc(nullptr, sizeof(TrackedAllocation) * N, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));
if (!buf) {
@@ -263,6 +264,9 @@ void* calloc_hook(size_t count, size_t size) noexcept
void memory_tracking_start()
{
// Trigger std::ostream initialization to avoid reporting it as leaks
std::cout << "Memory leak detection = " << 1 << std::endl;
SymInitialize(GetCurrentProcess(), NULL, TRUE);
using namespace p2pool;
@@ -272,7 +276,7 @@ void memory_tracking_start()
track_memory = true;
}
void memory_tracking_stop()
bool memory_tracking_stop()
{
using namespace p2pool;
@@ -298,6 +302,8 @@ void memory_tracking_stop()
}
SymCleanup(h);
return (total_leaks == 0);
}
NOINLINE void* operator new(size_t n) { return p2pool::allocate(n); }
@@ -313,7 +319,7 @@ NOINLINE void operator delete[](void* p, size_t) noexcept { p2pool::free_hook(p)
// cppcheck-suppress functionStatic
void memory_tracking_start() {}
// cppcheck-suppress functionStatic
void memory_tracking_stop() {}
bool memory_tracking_stop() { return true; }
namespace p2pool {