您的位置:首页 > 其它

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

2016-01-16 04:37 393 查看


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

 (2012-02-24 13:11:00)


转载▼

标签: 


it

分类: C/C加加
1、heap corruption detected

http://vopit.blog.51cto.com/2400931/645980

 

heap corruption detected:after normal block(#xxx) at 0x xxxxxxxx

crt detected that the application wrote to menory after end of heap buffer

这是典型的内存溢出错误,常在内存的delete处发生,而且一般在debug版本中可能出现,release版本中可能并不报错.

出现这个错误的原因一般都是操作new申请的内存溢出,因为在c++中,如果用new分配一段内存,操作的时候改变了该部分的大小,在delete时就会出错.比如说如下部分:

char* p=new char[5];

strcpy(p,"aaaaa");

delete[] p;

这段代码就会出错,因为申请了一个size为5的内存,但是strcpy过去了一个size为6的字符串,因此破坏了这个指针,运行debug版本的时候就会出现先前的错误,但是在release版本中,溢出一个字节的内存很有可能是没有错误的,然后潜在的隐患是肯定存在的,因此,我们在debug遇到这样的错误时候一定要仔细检查对new出的指针的操作.

 

           ***************拷贝时,内容超出申请的空间***********

           如memcpy的时候,size参数比new出来的空间还大

 

 

2、heap corruption detected after normal block

   http://hi.baidu.com/linzch/blog/item/3ceb4dedef60e7d9b31cb1e5.html

     *********一般是内存溢出错误。需要检查指针对内存的申请情况*************

 

3、 heap corruption detected

     http://blog.csdn.net/fjz13/article/details/2535126

    **********sscanf(str, "X", &pCmd[i]);中pCmd分配的空间不足************

 

4、HEAP CORRUPTION DETECTED:after Normal block(#***) at 0x****.CRT detected

   that application wrote memory after end of heap buffer.
    http://bbs.ednchina.com/BLOG_ARTICLE_2103923.HTM

   错误原因:以对内在操作的过程中,所写的地址超出了,所分配内在的边界

   解决办法:在可能出错的代码处,使用_CrtCheckMemory进行检测错误的现象是这样的:

 

简单内存调试技术(
4000
详见网址链接查看具体调试方法)


 

一 检查内存泄漏

添加以下语句:

#define CRTDBG_MAP_ALLOC

#include <stdlib.h>

#include <crtdbg.h>

比如:

int* p = new int[2];

*(p+2) = 1;

_ASSERTE( _CrtCheckMemory( ) );  //可以定位内存泄露的行

 

5、结构申请空间的时候别把

   p =(struct student *)malloc(sizeof(struct student));

   写成

   p =(struct student *)malloc(sizeof(struct student
*));

 

6、关于内存堆的问题  

   http://blog.sina.com.cn/s/blog_4ae178ba010110ys.html

 

7、C语言释放链表时的问题

   http://zhidao.baidu.com/question/38250738

 

 current = head;

 while (current != NULL)

 { 

     free(current);

     current=current->next;           

 }

 

改为

 

//释放字符子串链表空间

 current = head;

 while (current != NULL)

 { 

       temp=current;

       current=current->next; 

       free(temp);    

 }

  

8、内存越界的概念和调试方法

   http://www.chensj.cn/article/heap-corruption-conception-and-tips/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  heap