當我在發佈模式下編譯時,我對堆棧std :: string的重新分配有堆損壞。兩個DLL之間的堆損壞
實際上,在一個名爲Atc.dll
的DLL中,我調用另一個名爲Utilies.dll
的DLL中的函數。在Atc.dll
函數的最後,我有堆損壞。
這是我在Atc.dll
功能:
void CoreController::readConfigXMLFile()
{
ConfigFileManager configFileManager;
std::string pathXmlFilesTemp = configFileManager.getPathXMLFiles();
}
那麼,這是Utilies.dll
聲明的功能getPathXMLFiles
:
std::string ConfigFileManager::getPathXMLFiles()
{
bool err = false;
std::string ret = "";
if (!mParserXml.getNodeTextValue(sPathXmlFilesTag, ret))
{
err = true;
}
if (err)
{
ret = sPathXMLFilesDefault;
}
return ret;
}
注意:如果在這裏我不調用函數getNodeTextValue
,堆腐敗不會發生。因此,有功能getNodeTextValue
這是在同一個DLL比getPathXMLFiles
:
bool ParseXml::getNodeTextValue(const string& path, string& nodeValue)
{
DOMNode* child = XmlNode::getChildNodeByPath(xmlNode, path);
//If path is valid.
if(XmlNode::isValid(child))
{
char* str = XmlNode::getTextValue(child);
//If node contains text.
if(str != NULL)
{
nodeValue = str;
XmlNode::freeXMLString(str);
return true;
}
}
//Either path is not valid or node does not contain text
nodeValue = "";
return false;
}
而這正是堆損壞發生(STL):
void _Tidy(bool _Built = false,
size_type _Newsize = 0)
{ // initialize buffer, deallocating any storage
if (!_Built)
;
else if (this->_BUF_SIZE <= this->_Myres)
{ // copy any leftovers to small buffer and deallocate
_Elem *_Ptr = this->_Bx._Ptr;
if (0 < _Newsize)
_Traits::copy(this->_Bx._Buf, _Ptr, _Newsize);
this->_Alval.deallocate(_Ptr, this->_Myres + 1); // <-- HEAP CORRUPTION
}
this->_Myres = this->_BUF_SIZE - 1;
_Eos(_Newsize);
}
誰能告訴我,爲什麼這堆損壞發生和如何避免它?
感謝您的幫助。
你在這個過程中有多少個CRT?你是在分配一個還是在另一個分配? –
腐敗發生的地方很少發生腐敗的地方。使用一個好的調試分配器來解決這個問題,就像crtdbg.h –