Visual c++ 从Visual Studio 2010移动到2012后出现内存错误
我的库在Visual Studio 2010中运行得很好,但现在每当我在2012年运行编译的库时,都会出现以下内存错误:Visual c++ 从Visual Studio 2010移动到2012后出现内存错误,visual-c++,memory-management,memory-leaks,visual-studio-2012,Visual C++,Memory Management,Memory Leaks,Visual Studio 2012,我的库在Visual Studio 2010中运行得很好,但现在每当我在2012年运行编译的库时,都会出现以下内存错误: First-chance exception at 0x76884B32 in Example.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0101F3A0. First-chance exception at 0x76884B32 in Example.exe: Microsoft C+
First-chance exception at 0x76884B32 in Example.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0101F3A0.
First-chance exception at 0x76884B32 in Example.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0101F3A0.
Unhandled exception at at 0x76884B32 in Example.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0101F3A0.
First-chance exception at 0x76FF3541 (ntdll.dll) in Example.exe: 0xC0000005: Access violation reading location 0xFEFEFF02.
根据调用堆栈,每次返回wstring(cMD5.hexdigest())时都会出现错误代码>从以下代码调用:
wstring GetMachineHash() {
BYTE szHash[48];
LPBYTE pIdentifierHash;
ZeroMemory(szHash, 48);
MachineNameIdentifier cNameId;
pIdentifierHash = cNameId.GetIdentifierHash();
memcpy(szHash, pIdentifierHash, 16);
NetworkAdapterIdentifier cNetAdaptId;
pIdentifierHash = cNetAdaptId.GetIdentifierHash();
memcpy(szHash+16, pIdentifierHash, 16);
VolumeInfoIdentifier cVolInfo;
pIdentifierHash = cVolInfo.GetIdentifierHash();
memcpy(szHash+32, pIdentifierHash, 16);
MD5 cMD5(szHash, 48);
return wstring(cMD5.hexdigest());
}
如果您想知道我使用的是什么MD5类,它是Frank Thilo提供的一个端口,但是它被修改为返回LPBYTE而不是std::string,如下所示:
// return 16 byte md5 hash
LPBYTE MD5::hash() const {
if (!finalized)
return 0;
return (LPBYTE)digest;
}
// return hex representation of digest as string
LPTSTR MD5::hexdigest() const
{
if (!finalized)
return NULL;
LPTSTR szBuf = new TCHAR[33];
ZeroMemory(szBuf, 33);
for (int i=0; i<16; i++)
_stprintf_s(szBuf+i*2, 33, _T("%02X"), digest[i]);
szBuf[32]=0;
return szBuf;
}
//返回16字节md5哈希
LPBYTE MD5::hash()常量{
如果(!已完成)
返回0;
返回(LPBYTE)摘要;
}
//返回摘要作为字符串的十六进制表示形式
LPTSTR MD5::hexdigest()常量
{
如果(!已完成)
返回NULL;
LPTSTR szBuf=新TCHAR[33];
零存储器(szBuf,33);
对于(int i=0;idid)您是否找到过解决方案?@tofutim是的,它似乎是由于在代码中分配内存时出错造成的,部分原因是由于迁移到Visual Studio 2012。