1.下载编译https://github.com/0cch/luadbg

2.编写脚本1.txt

.load luadbg_v15
*.sympath+ srv*c:\MyServerSymbols*https://msdl.microsoft.com/download/symbols
x *!*CrtDumpMemoryLeaks*
bm *!*CrtDumpMemoryLeaks* ".logopen temp.txt;gu;.logclose;!lua analyse_leak.lua"
bl
gc

3.编写脚本analyse_leak.lua

function Sleep(n)
if n > then os.execute("ping -n " .. tonumber(n + ) .. " localhost > NUL") end
end print('---1\n')
local open = io.open local function read_file(path)
local file = open(path, "rb") -- r read mode and b binary mode
if not file then return nil end
local content = file:read "*a" -- *a or *all reads the whole file
file:close()
return content
end local function exec_from_io(cmd)
local path='temp.txt'
exec(string.format('.logopen %s', path))
exec(cmd)
Sleep()
exec('.logclose') local file = open(path, "rb") -- r read mode and b binary mode
if not file then return nil end
local content = file:read "*a" -- *a or *all reads the whole file
file:close()
return content
end print('---2\n')
local leak_str = read_file('temp.txt')
--print('---leak_str:', leak_str, '\n') --g:\temp\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(74) : {286} normal block at 0x000CD920, 4 bytes long.
print('---3\n') pe=
i=
while (true)
do
print('-----------------',i,'\n')
i = i+ p2b, p2e, addr= string.find(leak_str, 'normal block at ([^,]*),', pe)
print('---p2b, p2e, addr',p2b, p2e, addr, '\n')
if p2b==nil then break end cmd=string.format('!heap -p -a %s', addr)
print('---cmd:',cmd,'\n')
stacks=exec_tostring(cmd)
print('---stacks\n', stacks) pe = p2e
end

4. attach程序,执行 $<1.txt

5.程序运行,执行令他泄露,然后退出

6.程序会break到windbg里面,显示出泄露信息,比如在我这边的输出

0:000> !lua analyse_leak.lua
---1

---2

---3

----------------- 1

---p2b, p2e, addr 148 174 0x088C4FF8

---cmd: !heap -p -a 0x088C4FF8

---stacks
address 088c4ff8 found in
_DPH_HEAP_ROOT @ 57c1000
in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize)
8852c64: 88c4fd8 28 - 88c4000 2000
5360a65c verifier!AVrfDebugPageHeapAllocate+0x0000023c
778768c5 ntdll!RtlDebugAllocateHeap+0x0000003c
777d553c ntdll!RtlpAllocateHeap+0x000017dc
777d2f8a ntdll!RtlpAllocateHeapInternal+0x0000017a
777d2dfe ntdll!RtlAllocateHeap+0x0000003e
06225028 ucrtbased!heap_alloc_dbg_internal+0x00000198
06224e36 ucrtbased!heap_alloc_dbg+0x00000036
0622760a ucrtbased!_malloc_dbg+0x0000001a
0fb91257 mfc140ud!operator new+0x00000037
0fb912e6 mfc140ud!operator new+0x00000016
00d785aa MFCApplication2+0x000185aa
0fe5f48d mfc140ud!AfxDlgProc+0x0000005d
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a3ac48 USER32!UserCallDlgProcCheckWow+0x000002a8
74a3a307 USER32!DefDlgProcWorker+0x000000c7
74a3a224 USER32!DefDlgProcW+0x00000054
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a55913 USER32!UserCallWinProcCheckWow+0x000002d3
74a4b387 USER32!CallWindowProcW+0x00000097
0ff7fb7a mfc140ud!CWnd::DefWindowProcW+0x0000004a
0ff7fc6f mfc140ud!CWnd::Default+0x0000005f
0fe609b7 mfc140ud!CDialog::HandleInitDialog+0x00000137
0ff86d1d mfc140ud!CWnd::OnWndMsg+0x00000e2d
0ff8abb6 mfc140ud!CWnd::WindowProc+0x00000056
0ff7c1b8 mfc140ud!AfxCallWndProc+0x00000128
0ff7d1b5 mfc140ud!AfxWndProc+0x000000b5
0fcca0ad mfc140ud!AfxWndProcBase+0x0000006d
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a55913 USER32!UserCallWinProcCheckWow+0x000002d3
74a413da USER32!SendMessageWorker+0x0000028a
74a3ebef USER32!InternalCreateDialog+0x000011df
74a4f075 USER32!CreateDialogIndirectParamAorW+0x00000035

----------------- 2

---p2b, p2e, addr 296 322 0x088C4FF9

---cmd: !heap -p -a 0x088C4FF9

---stacks
address 088c4ff9 found in
_DPH_HEAP_ROOT @ 57c1000
in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize)
8852c64: 88c4fd8 28 - 88c4000 2000
5360a65c verifier!AVrfDebugPageHeapAllocate+0x0000023c
778768c5 ntdll!RtlDebugAllocateHeap+0x0000003c
777d553c ntdll!RtlpAllocateHeap+0x000017dc
777d2f8a ntdll!RtlpAllocateHeapInternal+0x0000017a
777d2dfe ntdll!RtlAllocateHeap+0x0000003e
06225028 ucrtbased!heap_alloc_dbg_internal+0x00000198
06224e36 ucrtbased!heap_alloc_dbg+0x00000036
0622760a ucrtbased!_malloc_dbg+0x0000001a
0fb91257 mfc140ud!operator new+0x00000037
0fb912e6 mfc140ud!operator new+0x00000016
00d785aa MFCApplication2+0x000185aa
0fe5f48d mfc140ud!AfxDlgProc+0x0000005d
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a3ac48 USER32!UserCallDlgProcCheckWow+0x000002a8
74a3a307 USER32!DefDlgProcWorker+0x000000c7
74a3a224 USER32!DefDlgProcW+0x00000054
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a55913 USER32!UserCallWinProcCheckWow+0x000002d3
74a4b387 USER32!CallWindowProcW+0x00000097
0ff7fb7a mfc140ud!CWnd::DefWindowProcW+0x0000004a
0ff7fc6f mfc140ud!CWnd::Default+0x0000005f
0fe609b7 mfc140ud!CDialog::HandleInitDialog+0x00000137
0ff86d1d mfc140ud!CWnd::OnWndMsg+0x00000e2d
0ff8abb6 mfc140ud!CWnd::WindowProc+0x00000056
0ff7c1b8 mfc140ud!AfxCallWndProc+0x00000128
0ff7d1b5 mfc140ud!AfxWndProc+0x000000b5
0fcca0ad mfc140ud!AfxWndProcBase+0x0000006d
74a634bb USER32!_InternalCallWinProc+0x0000002b
74a55913 USER32!UserCallWinProcCheckWow+0x000002d3
74a413da USER32!SendMessageWorker+0x0000028a
74a3ebef USER32!InternalCreateDialog+0x000011df
74a4f075 USER32!CreateDialogIndirectParamAorW+0x00000035

----------------- 3

---p2b, p2e, addr <out of memory> <out of memory> <out of memory>

用windbg 检查内存泄漏的更多相关文章

  1. 用mtrace检查内存泄漏

    http://blog.csdn.net/ixidof/article/details/6638066内存泄漏检查方法(for Linux) 如果你更想读原始文档, 请参考glibc info的&qu ...

  2. c++检查内存泄漏

    使用_CrtDumpMemoryLeaks()函数检查内存泄漏 #include <cstdio> #include <cstdlib> #include <crtdbg ...

  3. mtrace检查内存泄漏

    内存泄漏检查方法(for Linux) 如果你更想读原始文档, 请参考glibc info的"Allocation Debugging" 一章 (执行info libc);glib ...

  4. iOS开发 如何检查内存泄漏

    本文转载至 http://mobile.51cto.com/iphone-423391.htm 在开发的时候内存泄漏是不可避免的,但是也是我们需要尽量减少的,因为内存泄漏可能会很大程度的影响程序的稳定 ...

  5. ios--->instrument的leaks来检查内存泄漏

    instrument来检查内存泄漏 1.第一步打开 或者: 然后选择leaks 2.若此时编译出现如下问题,可能是非debug版本造成的,切换成debug版本即可 打开工程的Edit Scheme选项 ...

  6. UWP开发入门(十三)——用Diagnostic Tool检查内存泄漏

    因为.NET的垃圾回收机制相当完善,通常情况下我们是不需要关心内存泄漏的.问题人一但傻起来,连自己都会害怕,几个页面跳啊跳的,内存蹭蹭的往上涨,拉都拉不住.这种时候我们就需要冷静下来,泡一杯热巧克力. ...

  7. 基于WinDbg的内存泄漏分析

    在前面C++中基于Crt的内存泄漏检测一文中提到的方法已经可以解决我们的大部分内存泄露问题了,但是该方法是有前提的,那就是一定要有源代码,而且还只能是Debug版本调试模式下.实际上很多时候我们的程序 ...

  8. 记一次使用windbg排查内存泄漏的过程

    一.背景 近期有一个项目在运行当中出现一些问题,程序顺利启动,但是观察一阵子后发现内存使用总量在很缓慢地升高, 虽然偶尔还会往下降一些,但是总体还是不断上升:内存运行6个小时候从33M上升到80M: ...

  9. Android内存管理(14)*使用开源库LeakCanary检查内存泄漏

    1.简介 它是一个非常简单好用的内存泄漏检测工具库.可以轻松检测Activity,Fragment的内存泄漏.如果有内存泄漏,它会产生一个通知. 2.资料 官网: https://github.com ...

随机推荐

  1. dialog销毁不干净与弹出多个dialog问题

    1.关闭dialog的时候不销毁.重新打开然后影响页面的效果与样式. 原因: dialog的close()只是将html片段隐藏,并没有销毁移除. 解决方式: 打开dialog的时候在写onClose ...

  2. oracle截取字段中的部分字符串

    使用Oracle中Instr()和substr()函数: 在Oracle中可以使用instr函数对某个字符串进行判断,判断其是否含有指定的字符. 其语法为: instr(sourceString,de ...

  3. wait_activity

    wait_activity(self, activity, timeout, interval=1): android特有的 返回的True 或 False :Agrs: - activity - 需 ...

  4. ionic的actionsheet安卓样式不正常的坑及解决之道

    这是actionsheet该有的样子,可是android下变成了这样: 百度后,发现修改lonic.css,注释这段代码就可以了:

  5. HTTP、TCP、IP、协议

    HTTP(HyperText Transfer Protocol) 即超文本传输协议,现在基本上所有web项目都遵从HTTP协议(协议就是一种人为的规范). 目前绝大部分使用的都是HTTP/1.1版本 ...

  6. SSH连接虚拟机中的Ubuntu(转)

    摘要:主要是解决不能使用ssh远程Ubuntu的问题.使用的远程工具是putty.也可以使用xshell.ubunut12.0.4是装在虚拟机中的.不过这个应该没有什么影响. 一:问题的出现 前两天使 ...

  7. C# Windows IPSEC监控(仅此一家,别无分店)

    Windows IPSEC监控,使用C#编写,输出为一行字符串,可以按照既有IPSEC规则生成模板 using System; using System.Diagnostics; using Syst ...

  8. 重启uwsgi脚本备份

    NAME="identifyImg_uwsgi.init" if [ ! -n "$NAME" ];then echo "no arguments&q ...

  9. vue框架搭建

     1到网上下载node.js,安装,(新版node,包括了npm ).2下载Git安装.3.你需要的地方建一个文件夹.打开cmd,跳转到这个文件夹输入npm install -g vue-cli 完成 ...

  10. [LeetCode&Python] Problem 427. Construct Quad Tree

    We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...