首页 > 其他 > 详细

隐蔽的内存泄露

时间:2015-10-11 22:53:55      阅读:313      评论:0      收藏:0      [点我收藏+]

#include <stdio.h>

#include <stdlib.h>

int main(void){    

  int* p=NULL;  int i;

     p = (int *)malloc(6 * sizeof(int));      

  if (NULL == p) {    //判断是否为空        

    printf("内存分配出错!");        

    exit(1);    

  }  

  for(i=0;i<6;i++)  {   

    p++;  //导致内存泄露   

    *p = i;        

    printf("add=%d,%2d\n",p, *p);  

  }

     if (NULL != p) {    //判断是否为空        

      free(p);    //这句运行时出错   

        p=NULL;    

      }       return 0;

}

来源:http://c.biancheng.net/cpp/html/2752.html

隐蔽的内存泄露

原文:http://www.cnblogs.com/NCCM/p/4870097.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!