I have a structure:
typedef struct
{
char *ptr;
} A;
And a map
typedef std::map<std::wstring, A> myMap;
I have allocated memory for the ptr field using malloc while filling up the map.
To prevent memory leaks while clearing the map, I have the following code (actualMap is the actual map that I have to clear):
for (myMap::iterator iter = actualMap.begin(); iter != actualMap.end(); ++iter)
{
Free((iter->second).ptr);
}
actualMap.clear();
However, when I start the application normally, I’m getting an exception while Free is being executed. This exception is not being generated when I start the application directly via VS2010.
Have I missed something?
Thanks.
I recommend you use C++ std::string instead of raw pointer
A only has one pointer which points to string, so myMap can be: