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. spring4全注解web项目demo

    记得没接触框架的时候,写demo测试时真的很爽,新建web项目,然后随便写写servlet随便调试 框架越来越多,配置记不得了,整合容易出问题,集成新东西越来越少了,不敢动了. 这是个spring4的 ...

  2. python3.6 安装第三方库 pyCryptodome 实现AES加密

    起因 前端日子写完的Python入库脚本,通过直接读取配置文件的内容(包含了数据库的ip,数据库的用户名,数据库的密码),因为配置文件中的数据库密码是明文显示的,所以不太安全,由此对其进行加密. 编码 ...

  3. python储存数据的方式

    python储存数据的方式2017年10月13日 23:38:10 Nick_Spider 阅读数:59286 标签: redis 数据库 爬虫 存储 结构 更多 个人分类: 数据库 爬虫 pytho ...

  4. webstorm 自动编译ts

    1.在目录根目录添加tsconfig.json { "compileOnSave": false, "compilerOptions": { // 文件目录 & ...

  5. JAVA中的Set

    Set中存放的是没有重复的数据,下说记录一下使用中的小细节. 1.HashSet 区分大小写: Set<String> set1 = new HashSet<String>() ...

  6. 性能测试-9.Controller功能介绍

    Controller功能介绍 设计场景 配置场景 场景监控 一.设计场景 二.配置场景 规划场景(场景名.调度方式.运行方式.Initialize方式.Start Vusers方式.Duration方 ...

  7. Jsoup的学习

    一 . 什么是jsoup jsoup 是一款Java 的HTML解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuery的操作方法来 ...

  8. Spring Boot 揭秘与实战(二) 数据存储篇 - JPA整合

    文章目录 1. 环境依赖 2. 数据源 3. 脚本初始化 4. JPA 整合方案一 通过继承 JpaRepository 接口 4.1. 实体对象 4.2. DAO相关 4.3. Service相关 ...

  9. tomcat多实例的端口设置

    需要改4个端口 8080  8009 8005 8443 8080改成8081 8005改成8105 8009改成8109 8443 改成8543

  10. [LeetCode&Python] Problem 888. Fair Candy Swap

    Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that Ali ...