Jump to content
  • Advertisement
Sign in to follow this  
Tispe

Getting errors cleaning up a std::map

This topic is 2547 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I got a map which causes errors when I try to access its elements and free() some data. Please help me debug this.


struct DataFile
{
// pointer to buffer and size of buffer
unsigned int DataSize;
char* pData;
};



//Loading a file
DataFile FileContainer;
FileContainer.pData = (char*) malloc (sizeof(char)*lSize);



//clean up

std::map<DWORD, DataFile>::const_iterator end = DataMap.end();
for(std::map<DWORD, DataFile>::const_iterator it = DataMap.begin();it != end;++it)
{
if(it->second.pData != NULL)
{
free(it->second.pData);
}
}

DataMap.clear();


the "free(it->second.pData);" causes error:
Windows has triggered a breakpoint in Test.exe.

This may be due to a corruption of the heap, which indicates a bug in Test.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while Anim.exe has focus.

The output window may have more diagnostic information.

Share this post


Link to post
Share on other sites
Advertisement
There can be any number of causes for this. Double deletion, buffer overruns, other kinds of memory corruption. Try posting a complete, but minimal code sample that actually demonstrates your issue.

Share this post


Link to post
Share on other sites
I found it >< it was a double free().

I was copying the FileContainer from a vector to the map, then free() the vector element afterwards.

Thx for that quick response!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!