CRT detected that the application wrote to memory after end of heap buffer
来源:互联网 发布:java ssm框架项目实例 编辑:程序博客网 时间:2024/06/16 04:41
今天在项目中做修改时,发现以下的错误
CRT detected that the application wrote to memory after end of heap buffer
因为前段时间项目运行一直运行没问题,struct PcmLink 位于项目的头文件中声明的结构体。如下所示
struct PcmLink
{
short* pdata; //用于存储音频数据
int datalen;//数据大小
PcmLink* pNext;//用于记录音频下节点数据
};
今天突然出现这种错误。调试好一阵子。
顺便介绍一个函数用于内存泄露、堆操作出错、堆混乱问题_ASSERTE( _CrtCheckMemory( ) );
放于内存操作语句的后面便能立即Assert一个内存错误问题,应为一些对混乱问题可能到了应用程序的退出时或进行内存释放的时候才会出现,所以根本不知在哪个地方出错。一般编辑器的中断箭头只会指向你释放内存的语句。好了,话题回到调试上。
在我调试到语句
头文件
PcmLink*_pcmLinkMove; //遍历链表
源文件
_pcmLinkMove = NULL; //问题语句
_ASSERTE( _CrtCheckMemory( ) );
刚开始郁闷了,这么这条简单的语句会出错呢?即使改为
_pcmLinkMove = new Pcmwave(); //问题语句
仍然出问题
原来是在有的编辑器中结构体内嵌需要用typedef 定义一个新的类型,不然的话编辑器不知那是什么。
把结构体改为
typedef struct PcmLink
{
short* pdata; //用于存储音频数据
int datalen;//数据大小
PcmLink* pNext;//用于记录音频下节点数据
}PcmLink;
便可以了,(但是还有一个奇怪的问题就是换到自己的机器上运行居然没出现以上的问题,问题没办法重现。问题还是很模糊。
下面贴上解决内存方面的错误的一些方法
错误的现象是这样的:
在程序的开始处我申请了一块内存,中间对其进行了一些操作,在程序结束处,释放内存的时候,引起错误:
HEAP CORRUPTION DETECTED:after Normal block(#***) at 0x****.CRT detected that application wrote memory after end of heap buffer.
错误原因:
以对内在操作的过程中,所写的地址超出了,所分配内在的边界
解决办法:
在可能出错的代码处,使用_CrtCheckMemory进行检测
比如:
int* p = new int[2];
*(p+2) = 1;
_ASSERTE( _CrtCheckMemory( ) );
简单内存调试技术
一 检查内存泄漏
添加以下语句:
#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
以上代码第一行的作用是:输出调息信息的同时输出一些附加信息,例如分配该泄漏内存块的代码所在的文件名、行数。第二、第三行将 malloc 和 free 函数映射到“Debug”版本_malloc_dbg 和_free_dbg,以跟踪内存分配和释放。此映射只发生在调试版本。Release版本使用普通的 malloc 和 free 函数。
程序退出时调用_CrtDumpMemoryLeaks()输出调试信息到VC的调试窗口,也可以设置一个标志,让程序退出时自动输出调试信息,如下所示:
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG )|_CRTDBG_LEAK_CHECK_DF)
有时程序泄漏信息没有文件名和行数信息,例如:
Detected memory leaks!
Dumping objects ->
{52} normal block at 0x06AC2C88, 1234 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
上面的{52}表示该内存块的编号,大多数情况下是固定的。可以将该编号传递给 _CrtSetBreakAlloc以创建一个断点。执行将恰在分配该块以前中断,您可以向上追踪以确定哪个例程执行了错误调用。接着退出程序,观察"输出窗口"的内存泄露信息,验证实际内存分配的编号是不是和预设值相同,如果不相同,说明刚才的断点是无效的,需要尝试其它编号再次跟踪。
二 内存操作越界检查
有时出现内存操作越界,这时可以借助_CrtCheckMemory函数校验所有已分配内存块的有效性(例如内存块两侧边界是否被改写),通过在所有可疑点插入以下代码,定位发生内存越界的代码位置:ASSERT(_CrtCheckMemory());
同时也可以配合使用_CrtSetDbgFlag函数设置_CRTDBG_CHECK_ALWAYS_DF标志,这样每次分配/释放内存时,系统会自动调用_CrtCheckMemory,有助于快速捕获内存错误。
- CRT detected that the application wrote to memory after after the end of heap buffer
- CRT detected that the application wrote to memory after end of heap buffer 问题(转)
- CRT detected that the application wrote to memory after end of heap buffer
- CRT detected that the application wrote to memory after end of heap buffer
- 编译错误----CRT detected that the application wrote to memory after end of heap buffer
- 内存错误:CRT detected that the application wrote to memory after end of heap buffer
- 内存错误:CRT detected that the application wrote to memory after end of heap buffer
- CRT detected that the application wrote to memory after end of heap buffer
- CRT detected that the application wrote to memory after end of heap buffer
- 调试错误 - CRT detected that the application wrote to memory after end of heap buffer
- CRT detected that the application wrote to memory after end of heap buffer
- CRT detected that the application wrote to memory after end of heap buffer
- CRT detected that the application wrote to memory after end of heap buffer
- crt detected that the application wrote to memory after end of heap buffer
- 【debug】CRT detected that the application wrote to memory after end of heap buffer
- CRT detected that the application wrote to memory after end of heap buffer
- 释放内存free()错误:CRT detected that the application wrote to memory after end of heap buffer:内存访问违规
- [vs运行报错] CRT detected that the application wrote to memory after end of heap buffer
- DomainUpDown与NumericUpDown
- UVA 10474 用栈重排字母
- Ftp命令行传文件
- 数据库_基础代码<sql>
- Java Graphics_12
- CRT detected that the application wrote to memory after end of heap buffer
- jquery的一些基本的用法
- applicationWillResignActive
- python gearman的应用
- 使用JCharDet,获得文件的字符集编码!
- js中cookie的添加,删除,查询
- 有关Mat的函数
- 软件测试意识之主动思考
- BlackBerry 企业成功案例