mulle-testallocator is a leak and double free checker for tests (and at runtime). It builds upon mulle-allocator.
| Release Version | Release Notes |
|---|---|
| RELEASENOTES |
Debug support can be turned on and off with environment variables.
| Variable | Description |
|---|---|
MULLE_TESTALLOCATOR |
Turn on automatic tracing during startup. (See below) |
MULLE_TESTALLOCATOR_TRACE |
Trace setup, allocations and deallocations.
|
MULLE_TESTALLOCATOR_DONT_FREE |
Memory is not actually freed, this can be useful, when reuse of memory makes the trace too confusing. Obviously this can burn memory away quickly. |
MULLE_TESTALLOCATOR_FIRST_LEAK |
Only report the first leak if set to 1 or YES. |
MULLE_TESTALLOCATOR_MAX_SIZE |
Creates an out of memory condition if more than max size is allocated (in one call) |
Use mulle_malloc and friends instead of malloc in your code.
So instead of:
malloc( 1848);
calloc( 18, 48);
s = strdup( "VfL Bochum 1848");
realloc( s, 18);
free( s);write
mulle_malloc( 1848);
mulle_calloc( 18, 48);
s = mulle_strdup( "VfL Bochum 1848");
mulle_realloc( s, 18);
mulle_free( s);Now you can easily check for leaks using this mulle_testallocator library.
Just run your code with the environment variable MULLE_TESTALLOCATOR
set to YES.
mulle-testallocator will tell you your leaks when the executable exits.
This feature needs a C-compiler that handles
__attribute__(((constructor)).The order of constructor and atexit calls is dependent on the link order. To catch all leaks, it is advantageous to link mulle-testallocator ahead of all other code.
Or you can wrap your code inside the following piece of code:
mulle_testallocator_initialize();
mulle_default_allocator = mulle_testallocator;
{
mulle_malloc( 1848);
mulle_calloc( 18, 48);
s = mulle_strdup( "VfL Bochum 1848");
mulle_realloc( s, 18);
mulle_free( s);
}
mulle_testallocator_reset();and mulle_testallocator_reset will tell you about your leaks. You
don't need the 'constructor' support then.
All mulle_testallocator routines will check for erroneous frees and
wrong pointers.
Locate Objective-C leaks easily with
MULLE_TESTALLOCATOR_TRACE=2 \ MULLE_OBJC_PEDANTIC_EXIT=YES \ MULLE_OBJC_EPHEMERAL_SINGLETON=YES \ MULLE_OBJC_TRACE_INSTANCE=YES \ MULLE_OBJC_TRACE_METHOD_CALL=YES \ ./kitchen/Debug/myexeThen search for the leak address and you will see the method that allocated the leak.
You should use whole archive linking as otherwise the library may just
be omitted from the link. (The mulle-sde mark all-load will do this for you).
Use mulle-sde to add mulle-testallocator to your project:
mulle-sde dependency add --marks all-load,no-singlephase \
--github mulle-core \
mulle-testallocatorTo only add the sources of mulle-testallocator with dependency sources use clib:
clib install --out src/mulle-core mulle-core/mulle-testallocatorAdd -isystem src/mulle-core to your CFLAGS and compile all the sources that were downloaded with your project.
Use mulle-sde to build and install mulle-testallocator and all dependencies:
mulle-sde install --prefix /usr/local \
https://github.com/mulle-core/mulle-testallocator/archive/latest.tar.gzInstall the requirements:
| Requirements | Description |
|---|---|
| mulle-thread | 🔠 Cross-platform thread/mutex/tss/atomic operations in C |
| mulle-allocator | 🔄 Flexible C memory allocation scheme |
| mulle-stacktrace | 👣 Stracktrace support for various OS |
| mulle-atinit | 🤱🏼 Compatibility library for deterministic initializers |
| mulle-atexit | 👼 Compatibility library to fix atexit |
| mulle-dlfcn | ♿️ Shared library helper |
Download the latest tar or zip archive and unpack it.
Install mulle-testallocator into /usr/local with cmake:
cmake -B build \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_PREFIX_PATH=/usr/local \
-DCMAKE_BUILD_TYPE=Release &&
cmake --build build --config Release &&
cmake --install build --config ReleaseNat! for Mulle kybernetiK