首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

fread 开释heap内存时时会crash

2013-06-25 
fread 释放heap内存时时会crash帮忙看一下,最后在释放pBuff时会crash,why?#include stdio.h#include io

fread 释放heap内存时时会crash
帮忙看一下,最后在释放pBuff时会crash,why?



#include "stdio.h"
#include <iostream>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
using namespace std;

int main()
{
FILE* fpUpload = NULL;
if (NULL == (fpUpload = fopen("update", "r"))) {
printf("errno=%d \n", errno);
}
fseek(fpUpload, 0, SEEK_END);
int64_t size = ftell(fpUpload);
fseek(fpUpload, 0, SEEK_SET);
char* pBuff = new char(size+1);
if (NULL == pBuff) {
printf("error \n");
}

memset(pBuff, 0, size+1);
int readsize = fread(pBuff, 1, size, fpUpload);
        // pBuff[size] = '\n'; 
delete pBuff;
}
fread?new?delete
[解决办法]
char* pBuff = new char(size+1);....这算什么?小括号?

热点排行