CRT detected that the application wrote to memory after end of heap buffer.
很多人的解释都不一样, 我碰到的问题是,开辟的内存空间小于操作的内存空间.也就是说,我free的内存越界了.
这是我开辟链表结构体内存的代码:
PNODE Create() {
int len; //total count of nodes to be created.
int i;
int val; //temp value for the current node.
printf("enter the size of nodes:");
scanf("%d", &len);
PNODE pHead = (PNODE)malloc(sizeof(PNODE));
pHead->pNext = NULL;
PNODE pTail = pHead;
if(NULL == pHead) {
printf("allocate memory failed!");
exit();
}
for (i = ; i < len; i++)
{
PNODE pCur = (PNODE)malloc(sizeof(PNODE));
if(NULL == pCur) {
printf("allocate memory failed!");
exit();
}
printf("enter the %d-th value : ", i + );
scanf("%d", &val);
pCur->data = val;
//set the new node as the tail node.
pTail->pNext = pCur;
pCur->pNext = NULL;
pTail = pCur;
}
return pHead;
}
我是这样定义结构体的:
typedef struct node {
int data;
struct node * pNext;
} NODE, * PNODE;
删除元素时(报错的代码)为:
bool Delete(PNODE pHead, int pos, int *v) {
int i = -;
PNODE pNode = pHead;
while((i < pos - ) && pNode != NULL) {
pNode = pNode->pNext;
i++;
}
if(pos < i || pNode == NULL)
return false;
PNODE pTmp = pNode->pNext; //store to free later.
*v = pTmp->data;
pNode->pNext = pNode->pNext->pNext;
free(pTmp);
pTmp = NULL;
return true;
}
这段代码我翻来覆去地调试,发现所有的节点的指针域和数据域都是我期待的.就是在free的时候报了错.
原来是我开辟内存的时候,大小指定错了,应该把:
PNODE pNew = (PNODE)malloc(sizeof(PNODE));
改为:
PNODE pNew = (PNODE)malloc(sizeof(NODE));
开辟节点的大小应该为结构体的大小,其实我在'插入'新节点的时候,这行代码就写错了,但是不会报错.我觉得应该是没有释放.
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
今天调试测试代码时,发现在用完了new出来的内存buf后,在执行delete时报错了,具体信息为: HEAP_CORRUPTION_DETECTED: after Normal block(#908) ...
- C语言错误: 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 多是中间对其进行了一些操作,在程序结束处,释放内存 ...
- [vs执行报错] CRT detected that the application wrote to memory after end of heap buffer
CRT 是c/c++ run-time lib , 是程序执行时所需的核心库. 这个错误是由于以对内在操作的过程中.所写的地址超出了.所分配内在的边界 有个建议是: 1.内存申请多少释放多少,释放掉你 ...
- JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xfe
JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xfe 在使用Jni ...
- Fatal Error -26000: Not enough memory (12320 bytes) for “new buffer in LrwSrvNetTaskIt 问题解决及lr脚本心得
Fatal Error -26000: Not enough memory (12320 bytes) for “new buffer in LrwSrvNetTaskIt 问题解决及lr脚本心得 2 ...
- C++ 编译器内存错误 after Normal block。。。
解决 after Normal block(#908) at 0x399EC0. CRT detected that the application wrote to memory after end ...
- windows c++ 错误汇总
1.fatal error C1900 错误:fatal error C1900: “P1”(第“20081201”版)和“P2”(第“20080116”版)之间 Il 不匹配 检查之后发现jepgl ...
- heap corruption detected错误解决方法调试方法以及内存管理相关
1.heap corruption detected http://vopit.blog.51cto.com/2400931/645980 heap corruption detected:aft ...
- 内存溢出(heap corruption detected:)
今天又遇到了上次出现的bug,然后百度了一下,想起来这是内存溢出的毛病,故记录下来! 出现的问题就是这样: heap corruption detected: after normal block(# ...
随机推荐
- WPF小程序:贪吃蛇
原文地址:http://hankjin.blog.163.com/blog/static/337319372009535108234/ 一共两个文件:EasterEgg.xaml + EasterEg ...
- [BZOJ 1033] [ZJOI2008] 杀蚂蚁antbuster 【模拟!】
题目链接: BZOJ - 1033 题目分析 模拟!纯粹按照题目描述模拟! 这是一道喜闻乐见的经典模拟题! 我一共写了2遍,Debug 历时2天的所有晚自习 ... 时间超过 8h ... 我真是太弱 ...
- ExtJS简单的动画效果2(ext js淡入淡出特效)
Ext 开发小组则提供了 Fx 类集中处理了大部分常用的 js 动画特效,减少了我们自己手写代码的复杂度. 面我给出一个简单的实例代码,其中囊括了大部分的 Ext 动画效果: (注意导入js和css文 ...
- 哟哟哟,JAVA组装的聊天室,最简单的实现
太码多码码,总是多些感觉~~~ 打了快一个小时啊, 但看着一行一行的出来, 还是有成就感的~~:) VerySimpleChatServer.java import java.io.*; import ...
- -_-#【jQuery】data
.data() <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...
- GitHub上线Trending功能,帮你轻松找到有潜力的开源项目
转自:http://www.csdn.net/article/2013-08-14/2816574-Github-Trending-Open-Source-Project Github开源项目 摘要: ...
- @synthesize和@dynamic分别有什么作用?
@property有两个对应的词,一个是 @synthesize,一个是 @dynamic.如果 @synthesize和 @dynamic都没写,那么默认的就是@syntheszie var = _ ...
- 在eclipse下编译hadoop2.0源码
Hadoop是一个分布式系统基础架构,由apache基金会维护并更新.官网地址: http://hadoop.apache.org/ Hadoop项目主要包括以下4个模块: Hadoop Common ...
- linux 防火墙 iptables实例讲解
端口为例): 显示现有规则: iptables –L -n 清空现有规则表: iptables -F 黑名单:先允许所有数据包通过,后逐条添加黑名单规则. iptables –A INPUT–p tc ...
- MySQL用命令行复制表的方法
mysql中用命令行复制表结构的方法主要有一下几种: 1.只复制表结构到新表 ; 或 CREATE TABLE 新表 LIKE 旧表 ; 注意上面两种方式,前一种方式是不会复制时的主键类型和自增方式是 ...