Use of memory leak detection tool LEAKDIAG.

Source: Internet
Author: User

LeakDiag is a Microsoft tool to detect memory leak, the use of relatively simple

First to download a ftp://ftp.microsoft.com/PSS/Tools/Developer%20Support%20Tools/LeakDiag/

installed, the default is in C:/leakdiag.



Then write a test program to test
#include < stdio.h >
#include < windows.h >

int main ()
{
while (1)
{
char * c = new char [10];
printf ("%s", c);
Sleep (1000);
}
return 0;
}


Select Aaa.exe in LeakDiag
Then select Windows Heap allocator to track the use of Heap, start at start, wait a second to press log, and then stop
Will generate a log below the C:/leakdiag/logs

The key part is < leaks ver = "1.25.28.2201" >
< STACK Numallocs = "size" = "048" totalsize = "0240" >
< Stackstats >
< Sizestat size = "048" Numallocs = "a"/>
< Heapstat handle = "340000" Numallocs = "/>"
</stackstats >
< FRAME num = "0" DLL = "Aaa.exe" function = "" filename = "line =" "addr =" 0x407a72 "offset =" 0x00007a72 "/>
< FRAME num = "1" DLL = "Aaa.exe" function = "" filename = "line =" "addr =" 0x402ff2 "offset =" 0x00002ff2 "/>
< FRAME num = "2" DLL = "Aaa.exe" function = "" filename = "line =" "addr =" 0x402df9 "offset =" 0x00002df9 "/>
< FRAME num = "3" DLL = "Aaa.exe" function = "" filename = "line =" "addr =" 0x402dd6 "offset =" 0x00002dd6 "/>
< FRAME num = "4" DLL = "Aaa.exe" function = "" filename = "line =" "addr =" 0x40112f "offset =" 0x0000112f "/>
< FRAME num = "5" DLL = "Aaa.exe" function = "" filename = "line =" "addr =" 0x401038 "offset =" 0x00001038 "/>
< FRAME num = "6" DLL = "Aaa.exe" function = "" filename = "line =" "addr =" 0x401269 "offset =" 0x00001269 "/>
< FRAME num = "7" DLL = "KERNEL32.dll" function = "getsorttablesfileinfo" offset = "0xC" filename = "" line = "addr =" 0x7c5 989d5 "/>
< Stackid > 00524008 </stackid >
</STACK >
</leaks >


Where the Numallocs is the number of allocations, size is each time allocated, frame is leak call stack
The stack here only shows binary, because symbol doesn't match.

Add the corresponding PDB file path to [Tools]-[option]-symbol search path to get < leaks ver = "1.25.28.2201" >
< STACK Numallocs = "size" = "048" totalsize = "0288" >
< Stackstats >
< Sizestat size = "048" Numallocs = "Modified"/>
< Heapstat handle = "340000" Numallocs = "Modified"/>
</stackstats >
< FRAME num = "0" DLL = "Aaa.exe" function = "_heap_alloc_base" offset = "0xC2" filename = "malloc.c" line = "addr =" 0x4 07a72 "/>
< FRAME num = "1" DLL = "Aaa.exe" function = "_heap_alloc_dbg" offset = "0x1a2" filename = "dbgheap.c" line = "378" addr = "0x 402ff2 "/>
< FRAME num = "2" DLL = "Aaa.exe" function = "_nh_malloc_dbg" offset = "0x19" filename = "dbgheap.c" line = "248" addr = "0x40 2df9 "/>
< FRAME num = "3" DLL = "Aaa.exe" function = "_nh_malloc" offset = "0x16" filename = "dbgheap.c" line = "197" addr = "0x402dd6 "/>
< FRAME num = "4" DLL = "Aaa.exe" function = "operator new" offset = "0xF" filename = "new.cpp" line = "a" addr = "0x40112f" />
< FRAME num = "5" DLL = "Aaa.exe" function = "main" offset = "0x28" filename = "d:/test/aaa/test.cpp" line = "8" addr = "0x401" 038 "/>
< FRAME num = "6" DLL = "Aaa.exe" function = "maincrtstartup" offset = "0xe9" filename = "crt0.c" line = "206" addr = "0x40126 9 "/>
< Stackid > 00524008 </stackid >
</STACK >
</leaks >


The memory leak caused by Test.cpp line 8.
In addition, the log information generated by the above LeakDiag can be analyzed with Ldparser.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.