MEMTRACE (English) 
Sunday, April 06 2014 . 09:34 AM
What is MEMTRACE?
MEMTRACE is a utility designed for helping you in the tedious task of finding memory leaks in your C/C++ programs.

It is distributed as a source module that needs to be linked together with your project. This module is responsible of auditing your memory allocations and keep track of when and where they are freed or not.

Currently we are supporting both C and C++; under DOS, Windows, OS/2, Netware, and QNX; and compilers manufactured by Borland, Zorland/Zortech/Symantec/Digitalmars, Microsoft, and Watcom/Sybase/Powersoft. You can expect this list to grow considerably.

MEMTRACE has been succesfully tested in the following enviroments:
- Borland C++ 3.1: DOS16 real mode.
- Borland C++ 5.02: DOS16 real mode.
- Borland C++ Builder 6.0 SP4: Win32 console.
- DigitalMars 8.39: DOS16 real mode.
- DigitalMars 8.39: DOS32 protected mode.
- DigitalMars 8.39: Win32 console.
- Microsoft C++ 7.0: DOS16 real mode.
- Microsoft Visual C++ 1.52c: DOS16 real mode.
- Microsoft Visual C++ .NET 2003: Win32 console.
- OpenWatcom C++ 1.3: DOS16 real mode.
- OpenWatcom C++ 1.3: DOS16 real mode.
- OpenWatcom C++ 1.3: Win32 console.
- OpenWatcom C++ 1.3: OS/2 16.
- OpenWatcom C++ 1.3: OS/2 32.


How do I use MEMTRACE?
In order to use the MEMTRACE bundled features, you need to follow the following steps:
1) Include MEMTRACE.H in all your C/C++ modules you want to audit, just after your C/C++ include header and before your custom headers.
2) Include in your project MEMTRACE.CPP so it is linked with your executable. If your compiler does not support C++ you can also rename it as .C.
3) Define globally _MEMTRACE with a trace level or define _DEBUG.

If you do not include the 3) step, then no code is added to your application, so it is prepared to be released.

MEMTRACE does not require you include any kind of debug information in your application. Since it is portable, it could not take any advantage of it.

Currently predefined _MEMTRACE values are:
0: Shows no information.
1: Same as 0, but also shows critical ERRORS.
2: Same as 1, but also shows critical custom NOTES from the "log" function.
3: Same as 2.
4: Same as 3, but also shows application WARNINGS.
5: Same as 4, but also shows custom TRACE messages.
6: Same as 5.
The default level is 5.


What information MEMTRACE gives me?
The result information is saved in a file called MEMTRACE.LOG in the same directory as your executable.

This log file, includes 3 sections: "OPTIONS", "EXECUTION TRACE", "REPORT", "SUMARY" and "TOTALS".

The "OPTIONS"

The "EXECUTION TRACE SECTION" includes a TRACE of all the memory requests done by your application. It also includes all your debug information output by the log function.

The "REPORT"

The "SUMMARY"

The "TOTALS"


License
MEMTRACE is totally free, both for commercial, and private usage.
(c) Copyright 2002-2004 by Javier Gutierrez Chamorro


Can I see a sample report?
We compile against MEMTRACE the Demo.cpp file. Here is its source:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "memtrace.h"

int main (void)
{
int iCount;
char *acBlock1;
char *acBlock2;
char *acBlock3;
char acStatic[]="MEMTRACE";

log("Application start");
assert(1);

for (iCount=0; iCount<1; iCount++)
{
acBlock1=(char *) malloc(1000);
acBlock2=(char *) malloc(2000);
acBlock3=(char *) malloc(3000);

free(acBlock1);
free(acBlock2);
free(acBlock3);
}
for (iCount=0; iCount<1; iCount++)
{
acBlock1=new char[1000];
acBlock2=new char[2000];
acBlock3=new char[3000];

delete[] acBlock1;
delete[] acBlock2;
delete[] acBlock3;
}
acBlock1=strdup(acStatic);
realloc(acBlock1, 1000);
strcpy(acBlock1, acStatic);

memcpy(acBlock1, acStatic, 1000);
memcmp(acBlock1, acStatic, 100);
memset(acBlock1, 0, 1000);

strcpy(acStatic, "LiteralLiteral");
strcmp(acBlock1, acStatic);
strcat(acBlock1, acStatic);
free(acBlock1);

assert(1);
log("Application end");

return(0);
}


After running the generated executable, we get the file Demo.log with the following report:
------------------------------------------------------------------------------
: MEMTRACE v1.91 for C/C++ :
: A portable memory leak and buffer overrun/underrun detection library. :
: (c) Copyright 2002-2004 by Javier Gutierrez Chamorro :
------------------------------------------------------------------------------


OPTIONS
-------
Compilation timestamp: Oct 17 2004 17:07:02
Compiler: Watcom/OpenWatcom C++ 12.30 (Windows 32 bits)
Memory model: Flat (Release).
MEMTRACE reporting level: 5 (_MEMTRACE=5)


EXECUTION TRACE
---------------
[17/10/2004 17:09:22:00] Demo.cpp(16). int main( void )(). NOTE: Application start
log("Application start");

[17/10/2004 17:09:22:00] Demo.cpp(17). int main( void )(). NOTE: assert(1).
assert(1);

[17/10/2004 17:09:22:00] Demo.cpp(21). int main( void )(). TRACE: 0x003b1818=malloc(1000)
acBlock1=(char *) malloc(1000);

[17/10/2004 17:09:22:00] Demo.cpp(22). int main( void )(). TRACE: 0x003b2c10=malloc(2000)
acBlock2=(char *) malloc(2000);

[17/10/2004 17:09:22:00] Demo.cpp(23). int main( void )(). TRACE: 0x003b33e8=malloc(3000)
acBlock3=(char *) malloc(3000);

[17/10/2004 17:09:22:00] Demo.cpp(25). int main( void )(). TRACE: free(0x003b1818)
free(acBlock1);

[17/10/2004 17:09:22:00] Demo.cpp(26). int main( void )(). TRACE: free(0x003b2c10)
free(acBlock2);

[17/10/2004 17:09:22:00] Demo.cpp(27). int main( void )(). TRACE: free(0x003b33e8)
free(acBlock3);

[17/10/2004 17:09:22:00] (0). inline(). TRACE: 0x003b1818=new(1000)

[17/10/2004 17:09:22:00] (0). inline(). TRACE: 0x003b2c10=new(2000)

[17/10/2004 17:09:22:00] (0). inline(). TRACE: 0x003b33e8=new(3000)

[17/10/2004 17:09:22:00] (0). inline(). TRACE: delete(0x003b1818)

[17/10/2004 17:09:22:00] (0). inline(). TRACE: delete(0x003b2c10)

[17/10/2004 17:09:22:00] (0). inline(). TRACE: delete(0x003b33e8)

[17/10/2004 17:09:22:00] Demo.cpp(39). int main( void )(). TRACE: 0x003b1818=strdup(0x0006fe70)
acBlock1=strdup(acStatic);

[17/10/2004 17:09:22:00] Demo.cpp(40). int main( void )(). TRACE: 0x003b1818=realloc(0x003b1818, 1000)
realloc(acBlock1, 1000);

[17/10/2004 17:09:22:00] Demo.cpp(41). int main( void )(). TRACE: 0x003b1818=strcpy(0x003b1818, "MEMTRACE")
strcpy(acBlock1, acStatic);

[17/10/2004 17:09:22:00] Demo.cpp(43). int main( void )(). TRACE: 0x003b1818=memcpy(0x003b1818, 0x0006fe70, 1000)
memcpy(acBlock1, acStatic, 1000);

[17/10/2004 17:09:22:00] Demo.cpp(43). int main( void )(). WARNING: Call to memcpy() out of bounds.
memcpy(acBlock1, acStatic, 1000);

[17/10/2004 17:09:22:00] Demo.cpp(44). int main( void )(). TRACE: 0=memcmp(0x003b1818, 0x0006fe70, 100)
memcmp(acBlock1, acStatic, 100);

[17/10/2004 17:09:22:00] Demo.cpp(44). int main( void )(). WARNING: Call to memcmp() out of bounds.
memcmp(acBlock1, acStatic, 100);

[17/10/2004 17:09:22:00] Demo.cpp(45). int main( void )(). TRACE: 0x003b1818=memset(0x003b1818, 'x0', 1000)
memset(acBlock1, 0, 1000);

[17/10/2004 17:09:22:00] Demo.cpp(47). int main( void )(). TRACE: 0x0006fe70=strcpy(0x0006fe70, "LiteralLiteral")
strcpy(acStatic, "LiteralLiteral");

[17/10/2004 17:09:22:00] Demo.cpp(47). int main( void )(). WARNING: Call to strcpy() out of bounds.
strcpy(acStatic, "LiteralLiteral");

[17/10/2004 17:09:22:00] Demo.cpp(48). int main( void )(). TRACE: -1=strcmp(0x003b1818, "LiteralLiteral")
strcmp(acBlock1, acStatic);

[17/10/2004 17:09:22:00] Demo.cpp(48). int main( void )(). WARNING: Call to strcmp() out of bounds.
strcmp(acBlock1, acStatic);

[17/10/2004 17:09:22:00] Demo.cpp(49). int main( void )(). TRACE: 0x003b1818=strcat("LiteralLiteral", "LiteralLiteral")
strcat(acBlock1, acStatic);

[17/10/2004 17:09:22:00] Demo.cpp(50). int main( void )(). TRACE: free(0x003b1818)
free(acBlock1);

[17/10/2004 17:09:22:00] Demo.cpp(52). int main( void )(). NOTE: assert(1).
assert(1);

[17/10/2004 17:09:22:00] Demo.cpp(53). int main( void )(). NOTE: Application end
log("Application end");



REPORT
------


SUMARY
------
- malloc(): 4 call(s) (6009 bytes).
- calloc(): 0 call(s) (0 bytes).
- free(): 4 call(s).
- realloc(): 2 call(s) (2000 bytes).
- new: 3 call(s) (6000 bytes).
- delete: 3 call(s).
- new[]: 0 call(s) (0 bytes).
- delete[]: 0 call(s).
- strcpy(): 2 call(s).
- strcmp(): 1 call(s).
- strcat(): 1 call(s).
- memcpy(): 1 call(s).
- memcmp(): 1 call(s).
- memset(): 1 call(s).


TOTALS
------
- Execution time: 0.00 seconds.
- Peak memory used: 6000 bytes.
- Largest allocated block: 3000 bytes.
- Smallest allocated block: 9 bytes.
- Memory allocated: 7 blocks (12009 bytes).
- Memory freed: 7 blocks.
- Memory moved: 2 blocks (2000 Bytes).




Sponsors



Download
Get MEMTRACE 1.91 (275 Kb in ZIP format).


Links
- Official MEMTRACE's website: nikkhokkho.sourceforge.net/static.php?page=MEMTRACE

- Official author's website: www.javiergutierrezchamorro.com.