CrtIsValidHeapPointer problem with Oracle OCCI MetaData::getString
I am trying to get a name of a column from an oracle table using the MetaData class. I get a vector of MetaData objects from the ResultSet and then I loop over them executing the getString() function on each item, the problem is that on the second iteration, when exiting the loop to start a new iteration, it crashes on gives me CrtIsValidHeapPointer Assertion.
/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or开发者_开发知识库 it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData));
The data being pointed to by pUserData is actually valid, so I suspect my heap from the external API DLL is not the same as the CRT heap, the question is how do I resolve this issue?
my code:
std::vector<oracle::occi::MetaData> data = res->getColumnListMetaData();
for (std::vector<oracle::occi::MetaData>::iterator iter = data.begin(); iter != data.end(); iter++)
{
//Crash on second iteration after this statement
std::string s = (iter->getString(oracle::occi::MetaData::ATTR_NAME));
int i = iter->getInt(oracle::occi::MetaData::ATTR_DATA_TYPE);
std::cout << i << std::endl;
}
Does anybody have any suggestions or has anybody had this problem and solved it?
OS = Windows, VS2008, Oracle 11.2
Nothing in that code does any direct heap deallocation, although, of course, std::string
does allocate and deallocate heap memory. However, that shouldn't be a problem unless
- the heap is corrupted by some other operation or
- you pass
std::string
across executable boundaries, resulting in one executable (e.g. the DLL) allocating memory and another (e.g. the EXE) deallocating it.
You seem to be expecting the latter:
The data being pointed to by pUserData is actually valid, so I suspect my heap from the external API DLL is not the same as the CRT heap, the question is how do I resolve this issue?
That might indeed be the case. If you have control over both executables, you can make them both use the same dynamic RTL ("Multi-threaded Debug DLL" or something like that in VC).
However, in general it's not a good idea to have one executable free the resources of another one. Usually you should pass resources back to the API you obtained them from, so that it can be freed where it was allocated.
精彩评论