zoukankan      html  css  js  c++  java
  • windbg debug memory leakage

    program:

    #include "stdlib.h"
    #include <crtdbg.h>

    void testLeak1()
    {
     new int;
    }

    void testLeak2()
    {
     malloc(123);
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
     _CrtSetDbgFlag( _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_CHECK_CRT_DF );

     malloc(100);
     testLeak1();
     testLeak2();

     return 0;
    }

    CommandLine: D:\ctest\test\Debug\test.exe
    CommandLine: D:\ctest\test\Debug\test.exe
    Unable to deliver callback, Unable to deliver callback, 127127

    Symbol search path is: Symbol search path is: SRV*C:\MyLocalSymbols*http://msdl.microsoft.com/download/symbols
    SRV*C:\MyLocalSymbols*http://msdl.microsoft.com/download/symbols
    Executable search path is:
    Executable search path is:
    ModLoad: 00400000 0041b000   test.exe
    ModLoad: 00400000 0041b000   test.exe
    Unable to deliver callback, Unable to deliver callback, 00

    ModLoad: 7c920000 7c9b3000   ntdll.dll
    ModLoad: 7c920000 7c9b3000   ntdll.dll
    ModLoad: 7c800000 7c91e000   C:\WINDOWS\system32\kernel32.dll
    ModLoad: 7c800000 7c91e000   C:\WINDOWS\system32\kernel32.dll
    ModLoad: 10200000 10323000   C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\MSVCR90D.dll
    ModLoad: 10200000 10323000   C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\MSVCR90D.dll
    (fdc.e44): Break instruction exception(fdc.e44): Break instruction exception - code 80000003 (first chance)
     - code 80000003 (first chance)
    eax=00251eb4 ebx=7ffdb000 ecx=00000003 edx=00000008 esi=00251f48 edi=00251eb4
    eip=7c92120e esp=0012fb20 ebp=0012fc94 iopl=0         nv up ei pl nz na po nc
    cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202
    eax=00251eb4 ebx=7ffdb000 ecx=00000003 edx=00000008 esi=00251f48 edi=00251eb4
    eip=7c92120e esp=0012fb20 ebp=0012fc94 iopl=0         nv up ei pl nz na po nc
    cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202
    ntdll!DbgBreakPoint:
    7c92120e cc              int     3
    ntdll!DbgBreakPoint:
    7c92120e cc              int     3
    0:000> g
    0:000> g
    Detected memory leaks!
    Detected memory leaks!
    Dumping objects ->
    Dumping objects ->
    {80} {80} normal block at 0x00395F38, 123 bytes long.
    normal block at 0x00395F38, 123 bytes long.
     Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
     Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
    {79} {79} normal block at 0x00395EF8, 4 bytes long.
    normal block at 0x00395EF8, 4 bytes long.
     Data: <    > CD CD CD CD
     Data: <    > CD CD CD CD
    {78} {78} normal block at 0x00395E58, 100 bytes long.
    normal block at 0x00395E58, 100 bytes long.
     Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
     Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
    f:\dd\vctools\crt_bld\self_x86\crt\src\mbctype.c(593) : f:\dd\vctools\crt_bld\self_x86\crt\src\mbctype.c(593) : {4} {4} crt block at 0x00392E60, subtype 0, 544 bytes long.
    crt block at 0x00392E60, subtype 0, 544 bytes long.
     Data: <                > 02 00 00 00 A8 03 00 00 01 00 00 00 04 08 00 00
     Data: <                > 02 00 00 00 A8 03 00 00 01 00 00 00 04 08 00 00
    f:\dd\vctools\crt_bld\self_x86\crt\src\ioinit.c(136) : f:\dd\vctools\crt_bld\self_x86\crt\src\ioinit.c(136) : {2} {2} crt block at 0x00392110, subtype 0, 2048 bytes long.
    crt block at 0x00392110, subtype 0, 2048 bytes long.
     Data: <            `  |> 03 00 00 00 C1 0A 00 00 01 00 00 00 60 B9 99 7C
     Data: <            `  |> 03 00 00 00 C1 0A 00 00 01 00 00 00 60 B9 99 7C
    f:\dd\vctools\crt_bld\self_x86\crt\src\tidtable.c(394) : f:\dd\vctools\crt_bld\self_x86\crt\src\tidtable.c(394) : {1} {1} crt block at 0x00391EC0, subtype 0, 532 bytes long.
    crt block at 0x00391EC0, subtype 0, 532 bytes long.
     Data: <D               > 44 0E 00 00 FF FF FF FF 00 00 00 00 00 00 00 00
     Data: <D               > 44 0E 00 00 FF FF FF FF 00 00 00 00 00 00 00 00
    Object dump complete.
    Object dump complete.
    Unable to deliver callback, Unable to deliver callback, 00

    eax=00000000 ebx=00000000 ecx=7c800000 edx=0012fcb8 esi=7c92de50 edi=00000000
    eip=7c92e4f4 esp=0012fdf0 ebp=0012feec iopl=0         nv up ei pl zr na pe nc
    cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
    eax=00000000 ebx=00000000 ecx=7c800000 edx=0012fcb8 esi=7c92de50 edi=00000000
    eip=7c92e4f4 esp=0012fdf0 ebp=0012feec iopl=0         nv up ei pl zr na pe nc
    cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
    ntdll!KiFastSystemCallRet:
    7c92e4f4 c3              ret
    ntdll!KiFastSystemCallRet:
    7c92e4f4 c3              ret
    0:000> !heap -p -a 0x00395F38
    0:000> !heap -p -a 0x00395F38
        address 00395f38 found in
        address 00395f38 found in
        _HEAP @ 390000
          HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
            00395f10 0017 0000  [07]   00395f18    0009f - (busy)
            Trace: 004c
            7c98cf9a ntdll!RtlDebugAllocateHeap+0x000000e1
            7c969564 ntdll!RtlAllocateHeapSlowly+0x00000044
            7c938f01 ntdll!RtlAllocateHeap+0x00000e64
            102c103e MSVCR90D!_heap_alloc_base+0x0000005e
            102cfd76 MSVCR90D!_heap_alloc_dbg_impl+0x000001f6
            102cfb2f MSVCR90D!_nh_malloc_dbg_impl+0x0000001f
            102cfadc MSVCR90D!_nh_malloc_dbg+0x0000002c
            102db25b MSVCR90D!malloc+0x0000001b
        _HEAP @ 390000
          HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
            00395f10 0017 0000  [07]   00395f18    0009f - (busy)
            Trace: 004c
            7c98cf9a ntdll!RtlDebugAllocateHeap+0x000000e1
            7c969564 ntdll!RtlAllocateHeapSlowly+0x00000044
            7c938f01 ntdll!RtlAllocateHeap+0x00000e64
            102c103e MSVCR90D!_heap_alloc_base+0x0000005e
            102cfd76 MSVCR90D!_heap_alloc_dbg_impl+0x000001f6
            102cfb2f MSVCR90D!_nh_malloc_dbg_impl+0x0000001f
            102cfadc MSVCR90D!_nh_malloc_dbg+0x0000002c
            102db25b MSVCR90D!malloc+0x0000001b
    *** WARNING: Unable to verify checksum for test.exe
    *** WARNING: Unable to verify checksum for test.exe
            411a38 test!testLeak2+0x00000028
            41356c test!wmain+0x0000006c
            411968 test!__tmainCRTStartup+0x000001a8
            4117af test!wmainCRTStartup+0x0000000f
            7c817067 kernel32!BaseProcessStart+0x00000023

     
            411a38 test!testLeak2+0x00000028
            41356c test!wmain+0x0000006c
            411968 test!__tmainCRTStartup+0x000001a8
            4117af test!wmainCRTStartup+0x0000000f
            7c817067 kernel32!BaseProcessStart+0x00000023

     
    0:000> !heap -p -a 0x00395F38
    0:000> !heap -p -a 0x00395F38
        address 00395f38 found in
        address 00395f38 found in
        _HEAP @ 390000
          HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
            00395f10 0017 0000  [07]   00395f18    0009f - (busy)
            Trace: 004c
            7c98cf9a ntdll!RtlDebugAllocateHeap+0x000000e1
            7c969564 ntdll!RtlAllocateHeapSlowly+0x00000044
            7c938f01 ntdll!RtlAllocateHeap+0x00000e64
            102c103e MSVCR90D!_heap_alloc_base+0x0000005e
            102cfd76 MSVCR90D!_heap_alloc_dbg_impl+0x000001f6
            102cfb2f MSVCR90D!_nh_malloc_dbg_impl+0x0000001f
            102cfadc MSVCR90D!_nh_malloc_dbg+0x0000002c
            102db25b MSVCR90D!malloc+0x0000001b
            411a38 test!testLeak2+0x00000028
            41356c test!wmain+0x0000006c
            411968 test!__tmainCRTStartup+0x000001a8
            4117af test!wmainCRTStartup+0x0000000f
            7c817067 kernel32!BaseProcessStart+0x00000023

     
        _HEAP @ 390000
          HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
            00395f10 0017 0000  [07]   00395f18    0009f - (busy)
            Trace: 004c
            7c98cf9a ntdll!RtlDebugAllocateHeap+0x000000e1
            7c969564 ntdll!RtlAllocateHeapSlowly+0x00000044
            7c938f01 ntdll!RtlAllocateHeap+0x00000e64
            102c103e MSVCR90D!_heap_alloc_base+0x0000005e
            102cfd76 MSVCR90D!_heap_alloc_dbg_impl+0x000001f6
            102cfb2f MSVCR90D!_nh_malloc_dbg_impl+0x0000001f
            102cfadc MSVCR90D!_nh_malloc_dbg+0x0000002c
            102db25b MSVCR90D!malloc+0x0000001b
            411a38 test!testLeak2+0x00000028
            41356c test!wmain+0x0000006c
            411968 test!__tmainCRTStartup+0x000001a8
            4117af test!wmainCRTStartup+0x0000000f
            7c817067 kernel32!BaseProcessStart+0x00000023

     
    0:000> !heap -p -a 0x00395EF8
    0:000> !heap -p -a 0x00395EF8
        address 00395ef8 found in
        address 00395ef8 found in
        _HEAP @ 390000
          HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
            00395ed0 0008 0000  [07]   00395ed8    00028 - (busy)
            Trace: 004b
            7c98cf9a ntdll!RtlDebugAllocateHeap+0x000000e1
            7c969564 ntdll!RtlAllocateHeapSlowly+0x00000044
            7c938f01 ntdll!RtlAllocateHeap+0x00000e64
            102c103e MSVCR90D!_heap_alloc_base+0x0000005e
            102cfd76 MSVCR90D!_heap_alloc_dbg_impl+0x000001f6
            102cfb2f MSVCR90D!_nh_malloc_dbg_impl+0x0000001f
            102cfadc MSVCR90D!_nh_malloc_dbg+0x0000002c
            102db25b MSVCR90D!malloc+0x0000001b
            102bd691 MSVCR90D!operator new+0x00000011
            412fd5 test!testLeak1+0x00000025
            413567 test!wmain+0x00000067
            411968 test!__tmainCRTStartup+0x000001a8
            4117af test!wmainCRTStartup+0x0000000f
            7c817067 kernel32!BaseProcessStart+0x00000023

     
        _HEAP @ 390000
          HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
            00395ed0 0008 0000  [07]   00395ed8    00028 - (busy)
            Trace: 004b
            7c98cf9a ntdll!RtlDebugAllocateHeap+0x000000e1
            7c969564 ntdll!RtlAllocateHeapSlowly+0x00000044
            7c938f01 ntdll!RtlAllocateHeap+0x00000e64
            102c103e MSVCR90D!_heap_alloc_base+0x0000005e
            102cfd76 MSVCR90D!_heap_alloc_dbg_impl+0x000001f6
            102cfb2f MSVCR90D!_nh_malloc_dbg_impl+0x0000001f
            102cfadc MSVCR90D!_nh_malloc_dbg+0x0000002c
            102db25b MSVCR90D!malloc+0x0000001b
            102bd691 MSVCR90D!operator new+0x00000011
            412fd5 test!testLeak1+0x00000025
            413567 test!wmain+0x00000067
            411968 test!__tmainCRTStartup+0x000001a8
            4117af test!wmainCRTStartup+0x0000000f
            7c817067 kernel32!BaseProcessStart+0x00000023

     
    0:000> x *!_crtheap
    0:000> x *!_crtheap
    103161ec MSVCR90D!_crtheap = <no type information>
    103161ec MSVCR90D!_crtheap = <no type information>
    0:000> dd MSVCR90D!_crtheap
    0:000> dd MSVCR90D!_crtheap
    103161ec  00390000 00000000 00000000 00000000
    103161fc  00000000 00000000 00000000 00000000
    1031620c  00000000 00000000 00000000 00000000
    1031621c  00000000 00000000 00000000 00000000
    1031622c  00000000 00000000 00000000 00000000
    1031623c  00000000 00000000 00000000 00000000
    1031624c  00000000 00000000 00000000 00000000
    1031625c  00000000 ccd28a82 00003dde 00391ea0
    103161ec  00390000 00000000 00000000 00000000
    103161fc  00000000 00000000 00000000 00000000
    1031620c  00000000 00000000 00000000 00000000
    1031621c  00000000 00000000 00000000 00000000
    1031622c  00000000 00000000 00000000 00000000
    1031623c  00000000 00000000 00000000 00000000
    1031624c  00000000 00000000 00000000 00000000
    1031625c  00000000 ccd28a82 00003dde 00391ea0
    0:000> !heap -p -a 0x00395EF8
    0:000> !heap -p -a 0x00395EF8
        address 00395ef8 found in
        address 00395ef8 found in
        _HEAP @ 390000
          HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
            00395ed0 0008 0000  [07]   00395ed8    00028 - (busy)
            Trace: 004b
            7c98cf9a ntdll!RtlDebugAllocateHeap+0x000000e1
            7c969564 ntdll!RtlAllocateHeapSlowly+0x00000044
            7c938f01 ntdll!RtlAllocateHeap+0x00000e64
            102c103e MSVCR90D!_heap_alloc_base+0x0000005e
            102cfd76 MSVCR90D!_heap_alloc_dbg_impl+0x000001f6
            102cfb2f MSVCR90D!_nh_malloc_dbg_impl+0x0000001f
            102cfadc MSVCR90D!_nh_malloc_dbg+0x0000002c
            102db25b MSVCR90D!malloc+0x0000001b
            102bd691 MSVCR90D!operator new+0x00000011
            412fd5 test!testLeak1+0x00000025
            413567 test!wmain+0x00000067
            411968 test!__tmainCRTStartup+0x000001a8
            4117af test!wmainCRTStartup+0x0000000f
            7c817067 kernel32!BaseProcessStart+0x00000023

     
        _HEAP @ 390000
          HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
            00395ed0 0008 0000  [07]   00395ed8    00028 - (busy)
            Trace: 004b
            7c98cf9a ntdll!RtlDebugAllocateHeap+0x000000e1
            7c969564 ntdll!RtlAllocateHeapSlowly+0x00000044
            7c938f01 ntdll!RtlAllocateHeap+0x00000e64
            102c103e MSVCR90D!_heap_alloc_base+0x0000005e
            102cfd76 MSVCR90D!_heap_alloc_dbg_impl+0x000001f6
            102cfb2f MSVCR90D!_nh_malloc_dbg_impl+0x0000001f
            102cfadc MSVCR90D!_nh_malloc_dbg+0x0000002c
            102db25b MSVCR90D!malloc+0x0000001b
            102bd691 MSVCR90D!operator new+0x00000011
            412fd5 test!testLeak1+0x00000025
            413567 test!wmain+0x00000067
            411968 test!__tmainCRTStartup+0x000001a8
            4117af test!wmainCRTStartup+0x0000000f
            7c817067 kernel32!BaseProcessStart+0x00000023

     

  • 相关阅读:
    WPF Web Application 客户端下载目录及有趣的搜索问题
    判断表是否存在
    C#获取存储过程返回值和输出参数值
    模态对话框刷新问题
    sql Server 导出数据到脚本
    使用.NET 2.0中的秒表-Stopwatch类进行速度测试 (转一个程序员的自省)
    使用Redirect打开新窗口
    弹出层
    windows7安装配置IIS7.5过程图解
    控制文本框输入
  • 原文地址:https://www.cnblogs.com/cutepig/p/2007370.html
Copyright © 2011-2022 走看看