内存分配与释放问题请教

码大虾 码大虾 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
string AesEncryptor::EncryptString(string strInfor) {
int nLength = strInfor.length();
int spaceLength = 16 - (nLength % 16);
unsigned char* pBuffer = new unsigned char[nLength + spaceLength];
memset(pBuffer, '\0', nLength + spaceLength);
memcpy_s(pBuffer, nLength + spaceLength, strInfor.c_str(), nLength);
m_pEncryptor->Cipher(pBuffer, nLength + spaceLength);

// 这里需要把得到的字符数组转换成十六进制字符串
char* pOut = new char[2 * (nLength + spaceLength)];
memset(pOut, '\0', 2 * (nLength + spaceLength));
Byte2Hex(pBuffer, nLength + spaceLength, pOut);

string retValue(pOut);
delete[] pBuffer;
delete[] pOut;
return retValue;
}

在delete[] pOut时报错,弹出对话框:Windows 已在 ***.exe 中触发一个断点。其原因可能是堆被损坏
...全文
评论 8
收藏 已收藏
分享
返回顶部
码大虾
VC/MFC 16,551 成员 421,605 内容