I was wondering if anyone can spot what I am doing wrong with the following code. It is using COM and ADO to communicate with a MySQL database.
However, when I close the recordset, I do not get all the allocated memory back (according to the task manager.) I ran the perfmon app, and it too reported very severe memory leaks. The private bytes of my process grew exponentially as the program continued to run.
When I ran the program in debug mode, an exception is called when the Open method of the inRecords variable (see code, above). The debug window reports the following messages:
HEAP[DataAgent.exe]: Invalid Address specified to RtlFreeHeap( 130000, 12e930 )
First-chance exception in DataAgent.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
The program goes fine when I don't run it in debug mode (well, except for the memory creep, of course!)
Failing on RtlFreeHeap sounds suspicious to me - am I doing something stupid??? Is it something to do with with way I am passing in the inRecordset param? Is it wise to call RtlFreeHeap myself, explicity?
bool DatabaseManager::FindRecord(LPTSTR TableName, LPTSTR sqlCriterion, _RecordsetPtr &inRecordset )
if( ptrConnection == NULL )
sLastErrorDescription = L"A database connnection has not been established";
if( inRecordset == NULL )
sLastErrorDescription = L"The supplied recordset was uninstantiated";
/* construct SQL query, using the given criteria */
_bstr_t sqlQuery("SELECT * FROM ");
sqlQuery += _bstr_t(TableName);
sqlQuery += " WHERE ";
sqlQuery += _bstr_t(sqlCriterion);
sqlQuery += ";";
if( inRecordset->GetState() != adStateClosed )
inRecordset->CursorLocation = adUseClient;
inRecordset->Open(sqlQuery, ptrConnection.GetInterfacePtr(), adOpenDynamic, adLockBatchOptimistic,
hResult = S_OK;
catch( _com_error err )
sLastErrorDescription = err.Description();
hResult = err.Error();
As you can probably guess, I'm completely new to this ADO stuff, and any help would be greatly appreciated.