記一次 .NET 某工控視覺軟件 非托管泄漏分析( 二 )


2. 追蹤 ust 加持下的調用棧有了 ust 的加持,接下來就可以繼續分析,使用 !heap -s 觀察下 nt 堆的布局 。
0:000> !heap -sSEGMENT HEAP ERROR: failed to initialize the extentionNtGlobalFlag enables following debugging aids for new heaps:    stack back tracesLFH Key                   : 0x0000004c4f657ebfTermination on corruption : ENABLED          Heap     Flags   Reserv  Commit  Virt   Free  List   UCR  Virt  Lock  Fast                            (k)     (k)    (k)     (k) length      blocks cont. heap-------------------------------------------------------------------------------------0000000000060000 08000002   32576  17212  32576    430   161     6    1      0   LFH0000000000010000 08008000      64      8     64      5     1     1    0      00000000008810000 08001002    1088    500   1088     15     5     2    0      0   LFH...0000000029fb0000 08001002   88320  67408  88320  32559   343    47  189    1b7   LFH    External fragmentation  48 % (343 free blocks)0000000029870000 08001002     512      8    512      3     1     1    0      0...-------------------------------------------------------------------------------------從卦中看,commit 最大的也就是 67408k = 67M, 這和 13G 差的不是一星半點,如果你了解 NtHeap 的布局 , 應該知道當 分配內存 > 512k 的時候,會進入到 HEAP 的 VirtualAllocdBlocks 雙向鏈表中,言外之意就是當你覺得內存對不上的時候,就要觀察下這個鏈表了,即上圖中的 Virt blocks 列,可以看到 handle=0000000029fb0000 的 Virt blocks=189,接下來繼續下鉆 handle=0000000029fb0000 這個堆 。
0:000> !heap -h 0000000029fb0000SEGMENT HEAP ERROR: failed to initialize the extentionIndex   Address  Name      Debugging options enabled 23:   29fb0000    Segment at 0000000029fb0000 to 000000002a7b0000 (007eb000 bytes committed)    Segment at 0000000026070000 to 0000000026170000 (000ff000 bytes committed)    Segment at 0000000027d10000 to 0000000027f10000 (001f7000 bytes committed)    Segment at 00000000318a0000 to 0000000031ca0000 (00400000 bytes committed)    Segment at 0000000044a00000 to 0000000045200000 (005f1000 bytes committed)    Segment at 000000004ae90000 to 000000004be60000 (00efc000 bytes committed)    Segment at 000000005b3b0000 to 000000005c380000 (00e2e000 bytes committed)    Segment at 000000005d8c0000 to 000000005e890000 (00cf1000 bytes committed)    Segment at 000000005c380000 to 000000005d350000 (002e7000 bytes committed)    Flags:                08001002    ForceFlags:           00000000    Granularity:          16 bytes ...    Virtual Alloc List:   29fb0118    Unable to read nt!_HEAP_VIRTUAL_ALLOC_ENTRY structure at 0000000043500000    Uncommitted ranges:   29fb00f8

推薦閱讀