The mpatrol library is a powerful debugging tool that attempts to diagnose run-time errors that are caused by the wrong use of dynamically allocated memory. It acts as a malloc() debugger for debugging dynamic memory allocations, although it can also trace and profile calls to malloc() and free() too. If you don't know what the malloc() function or operator new[] do then this library is probably not for you. You have to have a certain amount of programming expertise and a knowledge of how to run a command line compiler and linker before you should attempt to use this.

Along with providing a comprehensive and configurable log of all dynamic memory operations that occurred during the lifetime of a program, the mpatrol library performs extensive checking to detect any misuse of dynamically allocated memory. All of this functionality can be integrated into existing code through the inclusion of a single header file at compile-time. On UNIX and Windows platforms (and AmigaOS when using GCC) this may not even be necessary as the mpatrol library can be linked with existing object files at link-time or, on some platforms, even dynamically linked with existing programs at run-time.

All logging and tracing output from the mpatrol library is sent to a separate log file in order to keep its diagnostics separate from any that the program being tested might generate. A wide variety of library settings can also be changed at run-time via an environment variable, thus removing the need to recompile or relink in order to change the library's behaviour.

A file containing a summary of the memory allocation profiling statistics for a particular program can be produced by the mpatrol library. This file can then be read by a profiling tool which will display a set of tables based upon the accumulated data. The profiling information includes summaries of all of the memory allocations listed by size and the function that allocated them and a list of memory leaks with the call stack of the allocating function. It also includes a graph of all memory allocations listed in tabular form, and an optional graph specification file for later processing by the dot graph visualisation package.

A file containing a concise encoded trace of all memory allocations and deallocations made by a program can also be produced by the mpatrol library. This file can then be read by a tracing tool which will decode the trace and display the events in tabular or graphical form, and also display any relevant statistics that could be calculated.

The mpatrol library has been designed with the intention of replacing calls to existing C and C++ memory allocation functions as seamlessly as possible, but in many cases that may not be possible and slight code modifications may be required. However, a preprocessor macro containing the version of the mpatrol library is provided for the purposes of conditional compilation so that release builds and debug builds can be easily automated.


The mpatrol library is freely distributable software and is covered by the GNU Lesser General Public License. The latest version is 1.5.1 and was released on the 16th of December, 2008.

The source code for all of the mpatrol releases is available for download from the SourceForge Subversion repository. Prebuilt binaries for specific platforms are not available here but may be found at other sites.

A gzipped tar archive of the source code for the older 1.4.8 release (including formatted documentation) can be downloaded from the SourceForge downloads area. In addition, several people have contributed code to mpatrol and some of that code has not made it into the mpatrol distribution. They are available from the same location as patches that can be applied to the mpatrol 1.4.8 distribution, but they are normally only useful for specific situations and are untested. See the mpatrol manual for a description of the patches.

A (not very up-to-date) list summarising the platforms that the mpatrol library has been built on (and the major features that are supported on each platform) is shown here. Note that it should be fairly easy to build mpatrol on a system that is not currently supported, but some work may be required to enable many of the advanced features that mpatrol might have support for on such a system.


Online documentation for the latest 1.5.1 release of mpatrol is available here. Alternatively, you may prefer to download the PDF versions of the mpatrol manual and quick reference card for the 1.5.1 release. Each release of mpatrol also contains UNIX manual pages for the library functions and associated command line tools.

Subscribe to the mpatrol library discussion group

Powered by

Browse the contents of the mpatrol archive.

Get mpatrol at Fast, secure and Free Open Source software downloads

Copyright © 1997-2008 Graeme S. Roy
Last updated on Tuesday 16th June, 2009.