mksqlite  2.5
A MATLAB interface to SQLite
Classes | Macros | Functions | Variables
heap_check.hpp File Reference

Memory leak detection helper. More...

#include <vector>
+ Include dependency graph for heap_check.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  HeapCheck
 Helperclass for memory leak and access violation detection. More...
 
struct  HeapCheck::tagHeader
 Memory block header. More...
 

Macros

#define HC_ASSERT(exp)   if (!(exp)) {HC_ASSERT_ERROR;} else
 
#define HC_NOTES(ptr, notes)   HeapCheck.UpdateNotes(ptr,notes)
 
#define HC_COMP_ASSERT(exp)   extern char _HC_CompAssert[(exp)?1:-1]
 Verifies design-time assumptions (exp) at compile-time.
 
#define HC_ABS(x)   (((x)>0)?(x):-(x))
 calculate absolute value
 
#define HC_ISPOWER2(x)   (!((x)&((x)-1)))
 check if is a power of 2
 
#define HC_ALIGNMENT   (sizeof(int))
 align to integer
 
#define HC_DOALIGN(num)   (((num)+HC_ALIGNMENT-1)&~(HC_ALIGNMENT-1))
 memory alignment
 
#define USE_HC_ASSERT
 Macro USE_HC_ASSERT must exist in every module which uses macro HC_ASSERT. More...
 

Functions

void HC_ReportAssert (const char *file, const char *lpFunctionName, long line)
 Standard assert routine used by macro HC_ASSERT. More...
 

Variables

class HeapCheck HeapCheck
 Instantiate HeapCheck object in main module.
 

Detailed Description

Memory leak detection helper.

Inspired by "Writing Bug-Free C Code" by Jerry Jongerius

See also
http://www.duckware.com/index.html
Author
Andreas Martin andim.nosp@m.arti.nosp@m.n@use.nosp@m.rs.s.nosp@m.ource.nosp@m.forg.nosp@m.e.net
Version
2.5
Date
2008-2017
Precondition
Warning
Bug:

Definition in file heap_check.hpp.


Class Documentation

◆ HeapCheck::tagHeader

struct HeapCheck::tagHeader

Memory block header.

Each memory block is surrounded by additional information: A preceding header stores who is responsible to this memory, some additional notes (comments) an a pointer to the end of the memory block (footer). By checking consitency of header and footer, one can test, if any close memory (write) accesses violation occures.

Definition at line 66 of file heap_check.hpp.

+ Collaboration diagram for HeapCheck::tagHeader:
Class Members
long lLineNumber line number or 0
const char * lpFilename filename or NULL
tagFooter * lpFooter pointer to footer, contiguous to memory block
const char * lpFunctionName function name
void * lpMem pointer to memory block (contiguous to this header space)
const char * lpNotes pointer to further notes or NULL

◆ HeapCheck::tagFooter

struct HeapCheck::tagFooter

Memory block footer (end marker)

The footer only holds a pointer to the memory block header and is used for consistence check only.

Definition at line 82 of file heap_check.hpp.

+ Collaboration diagram for HeapCheck::tagFooter:
Class Members
tagHeader * lpHeader pointer to header of this memory block

Macro Definition Documentation

◆ HC_ASSERT

#define HC_ASSERT (   exp)    if (!(exp)) {HC_ASSERT_ERROR;} else

Assert condition exp with reporting

Definition at line 24 of file heap_check.hpp.

Referenced by HeapCheck::VerifyPtr().

◆ HC_NOTES

#define HC_NOTES (   ptr,
  notes 
)    HeapCheck.UpdateNotes(ptr,notes)

Update field "notes" in memory block header

Definition at line 25 of file heap_check.hpp.

Referenced by MD5_func(), and regex_func().

◆ USE_HC_ASSERT

#define USE_HC_ASSERT
Value:
extern "C" void HC_ReportAssert ( const char*, const char*, long ); \
static int _HC_DoAssert ( const char* file, const char* func, int nLine ) \
{ \
HC_ReportAssert(file, func, nLine); \
HC_ASSERT(nLine); /* inhibit removal of unreferenced function */ \
return(0); \
}
void HC_ReportAssert(const char *file, const char *lpFunctionName, long line)
Standard assert routine used by macro HC_ASSERT.
Definition: heap_check.hpp:441

Macro USE_HC_ASSERT must exist in every module which uses macro HC_ASSERT.

Definition at line 37 of file heap_check.hpp.

Function Documentation

◆ HC_ReportAssert()

void HC_ReportAssert ( const char *  file,
const char *  lpFunctionName,
long  line 
)

Standard assert routine used by macro HC_ASSERT.

Parameters
[in]fileCallers filename
[in]lpFunctionNameCallers function name
[in]lineCallers line numer

Definition at line 441 of file heap_check.hpp.