OpenVPN
Macros
Dynamic Memory Allocation

Memory leaks, buffer overflows and underflows can be checked using cmocka. More...

Collaboration diagram for Dynamic Memory Allocation:

Macros

#define test_malloc(size)   _test_malloc(size, __FILE__, __LINE__)
 
#define test_calloc(num, size)   _test_calloc(num, size, __FILE__, __LINE__)
 
#define test_realloc(ptr, size)   _test_realloc(ptr, size, __FILE__, __LINE__)
 
#define test_free(ptr)   _test_free(ptr, __FILE__, __LINE__)
 

Detailed Description

Memory leaks, buffer overflows and underflows can be checked using cmocka.

To test for memory leaks, buffer overflows and underflows a module being tested by cmocka should replace calls to malloc(), calloc() and free() to test_malloc(), test_calloc() and test_free() respectively. Each time a block is deallocated using test_free() it is checked for corruption, if a corrupt block is found a test failure is signalled. All blocks allocated using the test_*() allocation functions are tracked by the cmocka library. When a test completes if any allocated blocks (memory leaks) remain they are reported and a test failure is signalled.

For simplicity cmocka currently executes all tests in one process. Therefore all test cases in a test application share a single address space which means memory corruption from a single test case could potentially cause the test application to exit prematurely.

Macro Definition Documentation

◆ test_calloc

#define test_calloc (   num,
  size 
)    _test_calloc(num, size, __FILE__, __LINE__)

Definition at line 1891 of file cmocka.h.

◆ test_free

#define test_free (   ptr)    _test_free(ptr, __FILE__, __LINE__)

◆ test_malloc

#define test_malloc (   size)    _test_malloc(size, __FILE__, __LINE__)

◆ test_realloc

#define test_realloc (   ptr,
  size 
)    _test_realloc(ptr, size, __FILE__, __LINE__)

Definition at line 1907 of file cmocka.h.

Referenced by torture_test_realloc(), and torture_test_realloc_set0().