关于内存的问题,求高人解答~
VS2008的工程,现在一运行到释放的地方,就报错:
Windows has triggered a breakpoint in PCIDataSource.exe.
This may be due to a corruption of the heap, which indicates a bug in PCIDataSource.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while PCIDataSource.exe has focus.
The output window may have more diagnostic information.
这是原代码,求高人指教
FILE *fp;
char *p;
//unsigned long *p_buffer;
/* 以只读方式打开文件 */
if(fopen_s (&fp,filepath,"r"))
{
AfxMessageBox("文件加载失败!");
exit(0);
}
fseek(fp,0L,SEEK_END); /* 定位到文件末尾 */
flen=ftell(fp); /* 得到文件大小 */
CString s;
s.Format("%u",flen);
AfxMessageBox(s);
p=(char *)malloc(flen+1); /* 根据文件大小动态分配内存空间 */
fseek(fp,0L,SEEK_SET); /* 定位到文件开头 */
fread(p,flen,1,fp); /* 一次性读取全部文件内容 */
//计算空格
for (m=0 ; m<flen ; m++)
{
if (p[m]==' ')
space_count++;
}
}
CString str1;
for (m=0 ; m<flen ; m=m+9)
{
if (m==flen-((flen-space_count)/2%4)*2)
{
for (k=0 ; k<4-(flen-space_count)/2%4 ; k++)
{
str1=str1+"00";
}
CString str_flen1,str_flen2,str_flen3;
for (k=0 ; k<((flen-space_count)/2%4)*2 ; k=k+2)
{
str_flen1=p[flen-((flen-space_count)/2%4)*2+k];
str_flen2=p[flen-((flen-space_count)/2%4)*2+k+1];
str_flen3=str_flen3+str_flen1+str_flen2;
}
nTmp=str1+str_flen3;
//AfxMessageBox(nTmp);
}
for (j=0;j<4;j++)
{
nTmp= p[m+2*j];
nTmp1=p[m+1+2*j];
str_nTmp=nTmp+nTmp1;
unsigned long num_mid1 = TransData(str_nTmp);
num_sum=(unsigned long)(num_sum + num_mid1*pow(256.0,(int)(3 - j)));//
}
num_sum=0;
}
p[flen]=0; /* 字符串结束标志 */
fclose(fp);
free(p);