<分区>
当运行时执行到语句 free(dat) 时出现一个对话框
Windows has triggered a breakpoint in project.exe. This may be due to a corruption of the heap, which indicates a bug in project.exe or any of the DLLs it has loaded.
while(1)
{
char *dat;
std::cout<<"Enter command\n";
memset(command, 0, 30);
std::cin>>command;
m_size = strlen(command)+2;
printf("send data Size: %d\n",m_size);
command[m_size-2] = '\r';
dat = (char*)malloc(m_size);
if(!dat)
{
printf("mem allocation failed");
}
else
{
memcpy(dat,command,sizeof(command));
ok = send_data(dat);
}
if(ok>0)
{
printf("send data: %s\n",dat);
}
free(dat);
}
//原始代码如下所示
int main()
{
char command[30];
While(1)
{....}
return 0;
}