ATLAS Offline Software
Classes | Namespaces | Functions | Variables
leakcheck.h File Reference

Pitifully simple leak checker for unit tests. Just verifies that allocations/deallocations match over an RAII region. More...

#include <malloc.h>
#include <unordered_set>
#include <iostream>
#include <cassert>
Include dependency graph for leakcheck.h:

Go to the source code of this file.

Classes

struct  Athena_test::LeakCheckDisable
 
struct  Athena_test::Leakcheck
 

Namespaces

 Athena_test
 functions & macros to test the difference between floats
 

Functions

void * newImpl (std::size_t size)
 
void * operator new (std::size_t size)
 
void deleteImpl (void *ptr) noexcept
 
void operator delete (void *ptr) noexcept
 
void operator delete (void *ptr, size_t) noexcept
 

Variables

std::unordered_set< void * > * Athena_test::allocs = nullptr
 

Detailed Description

Pitifully simple leak checker for unit tests. Just verifies that allocations/deallocations match over an RAII region.

Author
scott snyder snyde.nosp@m.r@bn.nosp@m.l.gov
Date
Nov, 2016 Overrides the standard new/delete functions, so should not be #included from any code that would be included in a library.

Definition in file leakcheck.h.

Function Documentation

◆ deleteImpl()

void deleteImpl ( void *  ptr)
noexcept

Definition at line 81 of file leakcheck.h.

82 {
83  if (Athena_test::allocs) {
85  disable.erase(ptr);
86  }
87  free(ptr);
88 }

◆ newImpl()

void* newImpl ( std::size_t  size)

Definition at line 65 of file leakcheck.h.

66 {
67  void* ptr = malloc(size);
68  if (Athena_test::allocs) {
70  disable.insert(ptr);
71  }
72  return ptr;
73 }

◆ operator delete() [1/2]

void operator delete ( void *  ptr)
noexcept

Definition at line 90 of file leakcheck.h.

91 {
92  deleteImpl(ptr);
93 }

◆ operator delete() [2/2]

void operator delete ( void *  ptr,
size_t   
)
noexcept

Definition at line 95 of file leakcheck.h.

96 {
97  deleteImpl(ptr);
98 }

◆ operator new()

void* operator new ( std::size_t  size)

Definition at line 75 of file leakcheck.h.

75  {
76  return newImpl(size);
77 }
Athena_test::allocs
std::unordered_set< void * > * allocs
Definition: leakcheck.h:51
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Athena_test::LeakCheckDisable::erase
void erase(void *p)
Definition: leakcheck.h:57
newImpl
void * newImpl(std::size_t size)
Definition: leakcheck.h:65
TrigInDetValidation_Base.malloc
malloc
Definition: TrigInDetValidation_Base.py:129
Athena_test::LeakCheckDisable::insert
void insert(void *p)
Definition: leakcheck.h:56
Athena_test::LeakCheckDisable
Definition: leakcheck.h:53
deleteImpl
void deleteImpl(void *ptr) noexcept
Definition: leakcheck.h:81