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. Linux分区和挂载的理解

    在工作中经常使用到Linux,对分区和挂载的概念一直都很模糊,对网上的信息进行了整理,方便理解. 1为什么要分区(需理解硬盘的组成) 1)数据的安全性,因为每个分区的数据是分开的.所以,当你需要将某个 ...

  2. 关于ArrayList中的iterator返回的事迭代器实例问题。

    Arraylist是一个具体的类,它并没有定义它自己的iterator()方法,,它只是从AbstractList 这个抽象类中继承了iterator()这个方法,而AbstractList 中的it ...

  3. unity3d 九宫密码锁

    using UnityEngine;using System.Collections.Generic;using System;using UnityEngine.EventSystems;using ...

  4. postman工具测试接口

    本篇文章主要介绍怎么在postman工具中进行接口的测试? 从以下几个方面进行介绍: 1.先介绍下接口测试 2.不同类型的接口请求方式如何在postman中进行测试 1.1 接口 什么是接口? 接口一 ...

  5. Code First 迁移更新数据库

    在使用 Code First 方式进行MVC程序设计中,更新数据库操作记录: 1.修改需要更新的Model,将应用程序重新编译 2.选择工具>库程序包管理器>程序包管理控制台,打开控制台, ...

  6. 多点触控 TouchAction

    #TouchAction #TouchAction方法是appium自已定义的新方法 # * 短按 (press) * 释放 (release) * 移动到 (moveTo) * 点击 (tap) * ...

  7. 2019.1.23 DFMEA for

  8. The databse returned no natively generated identity value问题

    com.cqupt.dayday.model 代码 package com.cqupt.dayday.model; import java.util.Date; /** * Created by I ...

  9. Struts2中的ModelDriven接口

    若没有实现ModelDriven的接口,Controll的代码会比较冗余,不能实现Controll和Model代码的分离 下面是没有实现ModelDriven接口的SuggestAction pack ...

  10. express安装中出现无此命令

    原来,最新express4.0版本中将命令工具分家出来了(项目地址:https://github.com/expressjs/generator),所以我们还需要安装一个命令工具,命令如下: 安装ex ...