Giter Site home page Giter Site logo

mulle-testallocator's Introduction

mulle-testallocator

๐Ÿ”„ C memory leak and double free checking

mulle-testallocator is a leak and double free checker for tests (and at runtime). It builds upon mulle-allocator.

Release Version Release Notes
Mulle kybernetiK tag Build Status RELEASENOTES

API

You can configure trace output and other properties of the Test Allocator via the API or environment variables.

Usage

Use mulle_testallocator for leak detection

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.

Note

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.

Manual method

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.

Tip

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/myexe

Then search for the leak address and you will see the method that allocated the leak.

You are here

Overview

Add

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).

Add as an individual component

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.

Install

Install with mulle-sde

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

Manual Installation

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

Author

Nat! for Mulle kybernetiK

mulle-testallocator's People

Contributors

codeon-nat avatar mulle-nat avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.