diff --git a/src/another_memcheck.cc b/src/another_memcheck.cc index 8cf0b17..f2b4621 100644 --- a/src/another_memcheck.cc +++ b/src/another_memcheck.cc @@ -19,7 +19,7 @@ namespace SC_AM_Internal { Stats *get_init_stats() { Stats *stats = reinterpret_cast( real_malloc(sizeof(Stats))); - stats->initialize(); + [[maybe_unused]] void *unused = new(stats) Stats{}; is_env_status = getenv("ANOTHER_MEMCHECK_QUIET") != nullptr ? ANOTHER_MEMCHECK_QUIET_EXISTS : ANOTHER_MEMCHECK_QUIET_NOT_EXISTS; @@ -80,9 +80,6 @@ namespace SC_AM_Internal { } Stats::Stats() : malloced_list_head(nullptr), malloced_list_tail(nullptr), deferred_node(nullptr), recursive_mutex(nullptr) { - } - - void Stats::initialize() { malloced_list_head = reinterpret_cast(real_malloc(sizeof(ListNode))); malloced_list_tail = reinterpret_cast(real_malloc(sizeof(ListNode))); malloced_list_head->next = malloced_list_tail; @@ -95,13 +92,12 @@ namespace SC_AM_Internal { deferred_node = nullptr; recursive_mutex = real_malloc(sizeof(std::recursive_mutex)); - void *unused = new(recursive_mutex) std::recursive_mutex{}; - (void)unused; + [[maybe_unused]] void *unused = new(recursive_mutex) std::recursive_mutex{}; std::atexit(exit_handler_stats); } - void Stats::cleanup() { + Stats::~Stats() { using std_recursive_mutex = std::recursive_mutex; ((std::recursive_mutex*)recursive_mutex)->~std_recursive_mutex(); real_free(recursive_mutex); @@ -221,7 +217,8 @@ namespace SC_AM_Internal { void exit_handler_stats() { if (SC_AM_Internal::stats != nullptr) { SC_AM_Internal::stats->print_status(); - SC_AM_Internal::stats->cleanup(); + using SCS_AM_INTERNAL_Stats = SC_AM_Internal::Stats; + SC_AM_Internal::stats->~SCS_AM_INTERNAL_Stats(); SC_AM_Internal::stats = nullptr; } } diff --git a/src/another_memcheck.h b/src/another_memcheck.h index 57c94a6..a4bebc3 100644 --- a/src/another_memcheck.h +++ b/src/another_memcheck.h @@ -1,6 +1,8 @@ #ifndef SEODISPARATE_COM_ANOTHER_MEMCHECK_H #define SEODISPARATE_COM_ANOTHER_MEMCHECK_H +#include + namespace SC_AM_Internal { // Forward declaration. struct Stats; @@ -48,15 +50,21 @@ namespace SC_AM_Internal { struct Stats { Stats(); + ~Stats(); + + // Disable copy. + Stats(Stats &other) = delete; + Stats& operator=(Stats &other) = delete; + + // Disable move. + Stats(Stats &&other) = delete; + Stats& operator=(Stats &&other) = delete; ListNode *malloced_list_head; ListNode *malloced_list_tail; ListNode *deferred_node; void *recursive_mutex; - void initialize(); - void cleanup(); - void *do_malloc(std::size_t size); void *do_calloc(std::size_t n, std::size_t size); void *do_realloc(void*, std::size_t size);