很多人的解释都不一样,  我碰到的问题是,开辟的内存空间小于操作的内存空间.也就是说,我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.的更多相关文章

  1. 内存错误:CRT detected that the application wrote to memory after end of heap buffer

    今天调试测试代码时,发现在用完了new出来的内存buf后,在执行delete时报错了,具体信息为: HEAP_CORRUPTION_DETECTED: after Normal block(#908) ...

  2. 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 多是中间对其进行了一些操作,在程序结束处,释放内存 ...

  3. [vs执行报错] CRT detected that the application wrote to memory after end of heap buffer

    CRT 是c/c++ run-time lib , 是程序执行时所需的核心库. 这个错误是由于以对内在操作的过程中.所写的地址超出了.所分配内在的边界 有个建议是: 1.内存申请多少释放多少,释放掉你 ...

  4. 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 ...

  5. 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 ...

  6. C++ 编译器内存错误 after Normal block。。。

    解决 after Normal block(#908) at 0x399EC0. CRT detected that the application wrote to memory after end ...

  7. windows c++ 错误汇总

    1.fatal error C1900 错误:fatal error C1900: “P1”(第“20081201”版)和“P2”(第“20080116”版)之间 Il 不匹配 检查之后发现jepgl ...

  8. heap corruption detected错误解决方法调试方法以及内存管理相关

    1.heap corruption detected http://vopit.blog.51cto.com/2400931/645980   heap corruption detected:aft ...

  9. 内存溢出(heap corruption detected:)

    今天又遇到了上次出现的bug,然后百度了一下,想起来这是内存溢出的毛病,故记录下来! 出现的问题就是这样: heap corruption detected: after normal block(# ...

随机推荐

  1. ArrayList的toArray

    ArrayList提供了一个将List转为数组的一个非常方便的方法toArray.toArray有两个重载的方法: 1.list.toArray(); 2.list.toArray(T[]  a); ...

  2. C# Linq-Aggregate

    The easiest to understand definition of Aggregate is that it performs an operation on each element o ...

  3. ARM机器码分析

    我们编写的汇编程序还是不够底层,CPU都是对机器码进行操作的,所以还需要用汇编器将汇编代码转换成机器码才能被CPU处理.下面举几个例子来说说分析ARM机器码的方法. 对编译连接之后得到的ELF进行反汇 ...

  4. [Hibernate] 基本增删查改

    本文记录,Java 应用通过 Hibernate 对数据库 MySQL 进行基本的增删改查操作,即CRUD. 本例子的目录结构如下 hibernate.cfg.xml 存储数据库信息,如数据库类型,账 ...

  5. HDU 1203 I NEED A OFFER! 01背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 解题思路:简单的01背包,用dp[i]表示花费不超过i时的最大可能性 状态转移方程 dp[i]= ...

  6. 使用 virtualenv

    关于virtualenv的资料: http://virtualenv-chinese-docs.readthedocs.org/en/latest/ 用的python3,但是搭建 Robot Fram ...

  7. 病毒侵袭持续中 - HDU 3065(AC自动机,判断子串个数)

    分析:依然是一个模板题,不过在写建立失败指针的地方竟然写错了三次....看来现在状态不太好.   代码如下: ============================================= ...

  8. Servlet的一些细节(1)

    1.  Servlet程序必须映射到一个URL地址 由于客户端是通过URL访问web服务器资源,所以Servlet程序必须映射到一个URL地址.这个工作在web.xml文件中使用<servlet ...

  9. 谈JSON在Ajax中的使用

    JSON是一种轻量级的数据交换格式.易于人阅读和编写,同时也易于机器解析和生成.AJAX是一种用于创建更好更快以及交互性更强的 Web 应用程序的技术.之前也曾介绍过在PHP语言中使用JSON的文章, ...

  10. JAVAEE filter总结

    1.  为什么需要filter? filter相当于客户端和服务器端之间的一扇门,就像保安一样.作用:比如说设置字符集和权限控制等等. 2.  细节; * . 只能对post请求起作用 *  .可以使 ...