Next: , Previous: The mpatrol command, Up: Utilities


9.2 The mleak command

Another utility program that is provided is called mleak and is useful for detecting memory leaks in log files produced by the mpatrol library. This program should be used if the mpatrol library could not finish writing the log file due to abnormal program termination (which would prevent the SHOWUNFREED option from working), but note that some of the unfreed allocations might have been freed if the program had terminated successfully.

The mleak command scans through an mpatrol log file looking for lines beginning with `ALLOC:' and `FREE:' but ignores lines beginning with `REALLOC:', so only the LOGALLOCS and LOGFREES options are necessary when running a program linked with the mpatrol library. Note that as a result of this, no attempt is made to account for resizing of memory allocations and so the total amount of memory used by the resulting unfreed allocations may not be entirely accurate.

This command will also read the unfreed allocations table produced by the SHOWUNFREED option in the log file if one is present. The entries in the table will be compared with the currently allocated entries and will be added if not already present. However, this behaviour can be disabled by supplying the --ignore option to the mleak command.

The mleak command can also be instructed to limit the number of lines of stack tracing information that it will display for each unfreed memory allocation. This is controlled by the --max-stack option which takes the maximum number of stack trace lines to display as an argument. If the number of lines is given as `0' (the default) then there will be no limit to the length of each stack trace.

The mleak command takes one optional argument which must be a valid mpatrol log filename but if it is omitted then it will use mpatrol.log as the name of the log file to use. The mleak command makes two passes over the log file so the file must be randomly-accessible. If the filename argument is given as `-' then the standard input file stream will be used as the log file. Note also that the mleak command supports the --help and --version options in common with the other mpatrol command line tools.

Note that mpatrol patch 5 (which can be downloaded from http://heanet.dl.sourceforge.net/sourceforge/mpatrol/mpatrol_patch5.tar.gz) contains the source code to a FORTRAN 90 program called condenseleaklog which offers similar facilities to the mleak command, as well as the ability to trim and filter stack traces.