使用WinDbg对非托管代码进行内存泄漏调试

时间:2018-08-21 05:05:38

标签: memory-leaks windbg

我正在使用WinDbg调试进程的某些转储中的潜在内存泄漏。

运行!heap -s以防重新启动:

Result:
************************************************************************************************************************
                                            NT HEAP STATS BELOW
************************************************************************************************************************
LFH Key                   : 0x000000db58680073
Termination on corruption : ENABLED
        Heap     Flags   Reserv  Commit  Virt   Free  List   UCR  Virt  Lock  Fast 
                            (k)     (k)    (k)     (k) length      blocks cont. heap 
-------------------------------------------------------------------------------------
0000005a8f4c0000 00000002   48620  24056  48228    280   269     8    3      0   LFH
0000005a8f2e0000 00008000      64      4     64      2     1     1    0      0      
0000005a8f5f0000 00001002    1472     96   1080      7     6     2    0      0   LFH
0000005a8f7b0000 00041002     508      8    508      5     1     1    0      0      
0000005a8f6b0000 00001002    3516   1544   3124     12    42     3    0      0   LFH
0000005a8f9b0000 00041002     900    136    508      0     2     1    0      0   LFH
0000005a8f860000 00001002     900    248    508      2    20     1    0      0   LFH
0000005a911e0000 00041002     508      8    508      5     1     1    0      0      
0000005aa9eb0000 00001002     900     44    508      3     3     1    0      0   LFH
0000005aad550000 00001002    1472     88   1080      5     6     2    0      0   LFH
0000005aad670000 00001002     508      8    508      5     1     1    0      0      
0000005aaf260000 00001002     452     32     60      7     3     1    0      0   LFH
0000005aaf230000 00001002    1472    136   1080      4     6     2    0      0   LFH
0000005ab14c0000 00001002     900    196    508     45    12     1    0      0   LFH
0000005ab6790000 00001002    1472     84   1080     10     4     2    0      0   LFH
0000005ab5b50000 00001002     900    188    508    128    16     1    0      0   LFH
0000005ab5c70000 00001002     452     40     60      1     3     1    0      0   LFH
0000005ab5cf0000 00001002     452     44     60      5     3     1    0      0   LFH
-------------------------------------------------------------------------------------

在执行一些操作后,对转储运行!heap -s:

Result:
************************************************************************************************************************
                                            NT HEAP STATS BELOW
************************************************************************************************************************
LFH Key                   : 0x000000db58680073
Termination on corruption : ENABLED
        Heap     Flags   Reserv  Commit  Virt   Free  List   UCR  Virt  Lock  Fast 
                            (k)     (k)    (k)     (k) length      blocks cont. heap 
-------------------------------------------------------------------------------------
0000005a8f4c0000 00000002  858020 438588 857628  43794  1185   167    8     ac   LFH
    Virtual address fragmentation  48 % (167 uncommited ranges)
0000005a8f2e0000 00008000      64      4     64      2     1     1    0      0      
0000005a8f5f0000 00001002    1472    164   1080      5     6     2    0      0   LFH
0000005a8f7b0000 00041002     508      8    508      5     1     1    0      0      
0000005a8f6b0000 00001002    7608   3448   7216     90   101     4    0      0   LFH
0000005a8f9b0000 00041002     900    152    508      4     2     1    0      0   LFH
0000005a8f860000 00001002    1920    604   1528      4    43     2    0      0   LFH
0000005a911e0000 00041002     508      8    508      5     1     1    0      0      
0000005aa9eb0000 00001002     900     56    508      7     5     1    0      0   LFH
0000005aad550000 00001002    1472    160   1080      7     8     2    0      0   LFH
0000005aad670000 00001002     508      8    508      5     1     1    0      0      
0000005aaf260000 00001002     452     32     60      7     3     1    0      0   LFH
0000005aaf230000 00001002    1472    392   1080     30    14     2    0      0   LFH
0000005ab14c0000 00001002     900    216    508     53    13     1    0      0   LFH
0000005ab6790000 00001002    1472    160   1080      4     5     2    0      0   LFH
0000005ab5b50000 00001002     900    188    508    130    18     1    0      0   LFH
0000005ab5c70000 00001002    1472     84   1080      5     5     2    0      0   LFH
0000005ab5cf0000 00001002    1472    100   1080      4     4     2    0      0   LFH
-------------------------------------------------------------------------------------

0000005a8f4c0000上的堆增长了很多。

运行!heap -stat -h 0000005a8f4c0000:

Resut:
heap @ 0000005a8f4c0000
group-by: TOTSIZE max-display: 20
    size     #blocks     total     ( %) (percent of total busy bytes)
    1000 2 - 2000  (19.45)
    146a 1 - 146a  (12.41)
    110 11 - 1210  (10.98)
    100 b - b00  (6.69)
    900 1 - 900  (5.47)
    468 2 - 8d0  (5.36)
    82e 1 - 82e  (4.97)
    800 1 - 800  (4.86)
    400 2 - 800  (4.86)
    4e8 1 - 4e8  (2.98)
    50 f - 4b0  (2.85)
    228 2 - 450  (2.62)
    410 1 - 410  (2.47)
    26c 1 - 26c  (1.47)
    238 1 - 238  (1.35)
    208 1 - 208  (1.23)
    30 8 - 180  (0.91)
    20 b - 160  (0.84)
    68 3 - 138  (0.74)
    60 3 - 120  (0.68)

我得到的大小和块数与干净启动完全相同。

下一步我该怎么做?如何找到导致0000005a8f4c0000增长的原因?

我应该在gflag中启用某些功能吗?

0 个答案:

没有答案