Department of Computer Science
Computer Systems Institute
ETH Zürich

[ download | introduction | usage | news | contributions | links ]

ccmalloc

If you want to remove memory leaks from your C or C++ programs or you experience strange bugs, probably due to pointer access to freed data, then ccmalloc may be the right tool for you. In general it can help you to track down memory related problems with C and C++ programs. It does not replace more sophistacted tools such as purify or valgrind, since it can not detect illegal memory reads, at least not all type of memory reads. But, first, it is distributed under GPL, second works already for Linux on various processesors and Solaris, and third is easy to port. It may also be slightly faster if you are only interested in checking for leaks. Last but not least, several user found it very easy to use.

usage

To use ccmalloc you just have to link it to your executable and run your program. It even works with optimized code. A log file will be generated which lists all memory leaks. Default is to print the results on stderr. If you want to specify a log file, you want to have additional statistics or check for illegal access to memory you have to change some parameters in an optional configuration file. More usage information is provided in the generic configuration file ccmalloc.cfg.

You may browse through the files and logs in the test suite. The files to be checked have a '.c' or '.cpp' suffix. The Makefile lists the commands for producing the executables linked with ccmalloc. The configuration file for each test case has a 'ccmalloc' prefix. Finally the log files have the name of the C or C++ compiler (actually the name of the C++ wrapper) as prefix. A simple example is the C program test_C_02.c. To produce the executable one could have used ccmalloc gcc -g -o test_C_02.exe test_C_02.c. Running the program produces quite a bit of leaks which are reported in the log file gcc_C_02.log. Note that I used CFLAGS=-g make to run the test suite. Otherwise the line number information would not have been included in the log files.

news

Version 0.3.4 added some initial support for SUN's Workshop Compiler CC. But hold your breath. It is not working propertly yet. Version 0.3.7 just fixed a bug in the 'ccmalloc' script to make it more compatible as a replacement of 'purify'. With this patch you can just replace the 'CC=gcc' option in makefiles with 'CC=ccmalloc gcc' and 'ccmalloc' will only link in the libraries if a binary is actually produced. Version 0.3.9 aims at making ccmalloc compatible with Redhat 7.1 and FreeBSD. The latest version 0.4.0 is a maintenance release. Please refer to NEWS for a more detailed listing of changes.

download

If you run a debian system then ccmalloc may already have been installed. Otherwise you can use the following sources for compilation and installation:

contributions

Thanks to all the users who sent in fixes and patches. They are already in my release queue and as soon my schedule is less tight, I will try to catch up with them. In particular many people asked about thread support. Here is a patch of Jon Schutz against version 0.3.8, which is supposed to add some preliminary thread support. It should also work with newer versions of ccmalloc. Recently, some users reported problems with this patch but I was not able to try it out myself.

At Ericsson the wrapper of ccmalloc for bootstrapping the libc malloc, has been modified by Lars Ekman to detect leaks of supposedly nonterminating programs, such as server applications. The idea is to explicitly call leak recording and leak reporting functions, when it is approriate from the application point of view. The printout is not as nice as with the original ccmalloc and the usage is more complicated. Here is an EMail containing the explanation, the modified wrapper code and an example.

Please feel free to contact me if something does not work as expected.

links

Last change
February 3, 2003
Armin Biere