mulle-testallocator is a leak and double free checker for tests (and at runtime). It builds upon mulle-allocator.
Release Version | Release Notes |
---|---|
RELEASENOTES |
You can configure trace output and other properties of the Test Allocator via the API or environment variables.
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_OBJC_PEDANTIC_EXIT=YES MULLE_TESTALLOCATOR=YES \ MULLE_OBJC_EPHEMERAL_SINGLETON=YES MULLE_OBJC_TRACE_INSTANCE=YES \ MULLE_OBJC_TRACE_METHOD_CALL=YES MULLE_TESTALLOCATOR_TRACE=2 \ ./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-testallocator
To only add the sources of mulle-testallocator with dependency sources use clib:
clib install --out src/mulle-core mulle-core/mulle-testallocator
Add -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.gz
Install 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 Release
Nat! for Mulle kybernetiK