Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. memory leak in CADORecordset?

memory leak in CADORecordset?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiolinuxperformance
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tuxyboy
    wrote on last edited by
    #1

    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?

    P 1 Reply Last reply
    0
    • T tuxyboy

      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?

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      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.

      T 1 Reply Last reply
      0
      • P prasad_som

        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.

        T Offline
        T Offline
        tuxyboy
        wrote on last edited by
        #3

        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.

        P 1 Reply Last reply
        0
        • T tuxyboy

          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.

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #4

          Is the value you are tring to assing is CString ? It looks like , you are facing similar situation, I faced in past. Refer, this[^] post. Though, I never got satisfactory answer.

          T 1 Reply Last reply
          0
          • P prasad_som

            Is the value you are tring to assing is CString ? It looks like , you are facing similar situation, I faced in past. Refer, this[^] post. Though, I never got satisfactory answer.

            T Offline
            T Offline
            tuxyboy
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups