memory leak ADO open function

  ado, c++, windows

In the following code scenario, after calling func1() a memory leak is observed.
CoUninitialize() was expected to release that memory. But I guess that’s not happening.
Is there anything more to add?

void TestDBConnections(){
    int iErrorCode = 0;
    _ConnectionPtr m_pConnection;
    HRESULT hr;
    try
    {
        TESTHR(hr = m_pConnection.CreateInstance(__uuidof(Connection)));
        
        if (SUCCEEDED(hr))
        {
            _bstr_t sCS("DSN=xxxxx;UID=xxxxx;PWD=xxxxx;Provider=SQLNCLI11;Driver={SQL Server Native Client 11.0};DataTypeCompatibility=80;Initial Catalog=xxxx;Server=xxxxx;MultiSubnetFailover=No;"), sU, sP;
            m_pConnection->Open(sCS, sU, sP, adConnectUnspecified); 
            m_pConnection->Close();
        }
    }
    catch (_com_error &e)
    {
        cout << "Com exception" << e.ErrorMessage() << endl;
    }
    

}

int func1(){
    CoInitializeEx(NULL, COINIT_MULTITHREADED);
    for (int j = 0; j < 100; j++)
    {
        TestDBConnections();
    }
    CoUninitialize();
    return 0;
}

Source: Windows Questions

LEAVE A COMMENT