memory leak in CADORecordset?
-
Leakfinder shows memory leak in ADORecordset::Getfieldvalue function the function is called in a loop on a separate thread. BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, _variant_t& vtValue) { try { vtValue = m_pRecordset->Fields->GetItem(lpFieldName)->Value; <-leak return TRUE; } catch(_com_error &e) { dump_com_error(e); return FALSE; } } c:\My Projects\PCSRecord_Plus\Code\Shell\LeakFinder.cpp (903): CMallocSpy::PostAlloc 77573015 (ole32): (filename not available): void * __stdcall CSpyMalloc_Alloc(struct IMalloc *,unsigned long) 77114B52 (OLEAUT32): (filename not available): public: void * __thiscall APP_DATA::AllocCachedMem(unsigned long) 77114C7F (OLEAUT32): (filename not available): _SysAllocStringByteLen@8 77114CF0 (OLEAUT32): (filename not available): _ErrStringCopyNoNull@8 7713D325 (OLEAUT32): (filename not available): _VariantCopy@8 c:\program files\microsoft visual studio\vc98\include\comutil.h (1295): _variant_t::operator= c:\My Projects\PCSRecord_Plus\Code\Client\ADORecordset.cpp (968): CADORecordset::GetFieldValue what do you think?
-
Leakfinder shows memory leak in ADORecordset::Getfieldvalue function the function is called in a loop on a separate thread. BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, _variant_t& vtValue) { try { vtValue = m_pRecordset->Fields->GetItem(lpFieldName)->Value; <-leak return TRUE; } catch(_com_error &e) { dump_com_error(e); return FALSE; } } c:\My Projects\PCSRecord_Plus\Code\Shell\LeakFinder.cpp (903): CMallocSpy::PostAlloc 77573015 (ole32): (filename not available): void * __stdcall CSpyMalloc_Alloc(struct IMalloc *,unsigned long) 77114B52 (OLEAUT32): (filename not available): public: void * __thiscall APP_DATA::AllocCachedMem(unsigned long) 77114C7F (OLEAUT32): (filename not available): _SysAllocStringByteLen@8 77114CF0 (OLEAUT32): (filename not available): _ErrStringCopyNoNull@8 7713D325 (OLEAUT32): (filename not available): _VariantCopy@8 c:\program files\microsoft visual studio\vc98\include\comutil.h (1295): _variant_t::operator= c:\My Projects\PCSRecord_Plus\Code\Client\ADORecordset.cpp (968): CADORecordset::GetFieldValue what do you think?
VariantCopy
does not frees memory allocated at destination, you need to do that. Problem is , if you are running this function in loop, and using same variable for getting field value for each item in loop, you will definitely leak memory. You need to clear it first. Have a look at VariantCopy[^]. Just to add,VariantCopy
is used in assignment operator / copy c'tor of_variant_t
. -
VariantCopy
does not frees memory allocated at destination, you need to do that. Problem is , if you are running this function in loop, and using same variable for getting field value for each item in loop, you will definitely leak memory. You need to clear it first. Have a look at VariantCopy[^]. Just to add,VariantCopy
is used in assignment operator / copy c'tor of_variant_t
.thanks for the reply. I tried that already. Nothing changes. BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, _variant_t& vtValue) { try { vtValue.Clear(); vtValue = m_pRecordset->Fields->GetItem(lpFieldName)->Value; return TRUE; } catch(_com_error &e) { dump_com_error(e); return FALSE; } } I also tried clearing the vtValue in the calling function before GetFieldValue, same thing.
-
thanks for the reply. I tried that already. Nothing changes. BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, _variant_t& vtValue) { try { vtValue.Clear(); vtValue = m_pRecordset->Fields->GetItem(lpFieldName)->Value; return TRUE; } catch(_com_error &e) { dump_com_error(e); return FALSE; } } I also tried clearing the vtValue in the calling function before GetFieldValue, same thing.
-
Well, I'm using the _variant_t class to have a general solution for getting the values from the recordsetfields, but yes most of the times they are strings, but at that point of the execution I didn't converted them to CString. I also tried without using _variant_t, using VARIANT and BSTR and _bstr_t. Though the place changes I still have memory leaks somewhere. I also have issues with CString Allocbuffer. I'm close to pulling my hair one by one. Have been playing with this for weeks now. These functions are called on a separate thread, I'm using a jobmanager class I wrote. What I was thinking about lately it might by due to threading issues. Or is it general, but others haven't noticed yet? I should build a single threaded test program.