//读取文件发送
ifstream infile;
infile.open(path, ios::in | ios::binary);
if (!infile.is_open())
{
WsLogUtil::log("file open fail: %s", path);
return;
}
infile.seekg(0, infile.end);
int file_length = infile.tellg();
infile.seekg(0, infile.beg);
char *buffer = new char(file_length);
infile.read(buffer, file_length);
上面一段代码,后面的发送过程中,小文件能正常发送。大文件会出现内存崩溃:malloc(): memory corruption
通过打印,每次打印出错的位置都不一样。
后来请来大神帮忙,三下五除二,定位到了问题。
上面第12行。定义数组时,用了小括号。。。。。。
更正为 char *buffer = new char[file_length]; 问题解决。
总结一下
C++远程调试的方法
打印
屏蔽代码