谁能帮助我,为什么我在尝试释放分配的内存时收到错误消息:检测到堆损坏。CTR 检测到应用程序在堆缓冲区结束后写入内存。
char *ff (char *s){
char *s1 = new char [strlen(s)];
strcpy(s1, s);
return s1;
}
int _tmain(int argc, _TCHAR* argv[])
{
char *s = new char [5];
strcpy(s, "hello");
char *s2 = ff(s);
delete []s; // This works normal
delete []s2; // But I get an error on that line
return 0;
}