Memory Leak in

I am running a simple ADO test.   I am using VC++ 6 on Windows XP.  When evaluating the code with Rational Purify I get a memeory leak.   What am I doing wrong?


#include "StdAfx.h"
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
              rename("EOF", "EndOfFile")

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)

      ADODB::_ConnectionPtr      _cnn;

            HRESULT hr;
            hr    = _cnn.CreateInstance( __uuidof(ADODB::Connection ) );
            _cnn->Open("DSN=ZIPS", L"",L"", ADODB::adModeUnknown);
      }catch (...)

      return 0;


[W] MLK: Memory leak of 4096 bytes from 1 block allocated in ADODB::Connection15::Open(_bstr_t,_bstr_t,_bstr_t,long) [UnitTests.exe]
        Distribution of leaked blocks
        Allocation location
            VirtualAlloc   [KERNEL32.dll]
            ADODB::Connection15::Open(_bstr_t,_bstr_t,_bstr_t,long) [msado15.tli:367]
                inline HRESULT Connection15::Open ( _bstr_t ConnectionString, _bstr_t UserID, _bstr_t Password, long Options ) {
             =>     HRESULT _hr = raw_Open(ConnectionString, UserID, Password, Options);
                    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
                    return _hr;
Who is Participating?
Everything looks fine.... I personallly moved away from ADO and I use pure ODBC API.  I found a nifty little library from Gehtsoft (GSODBC) that wrapped up most all of the functionality I needed and best of all I was able to eliminate COM from my project.

It would also be interesting to know if Rational wasn't making a mistake with tracking the VirtualAlloc.  One could do a test and run your app 50 times and see if it truely is leaking the memory or if Purify wasn't mistaken.

Just my 2 cents...
nicoleheritageAuthor Commented:
I am using an ODBC connection to mircosoft Access for testing
nicoleheritageAuthor Commented:
I agree with your 2 cents and will be heading in that directions.


If you need a copy of the ODBC library, I would be more that happy to supply you one...  I think I origionally got mine off off but I remember it taking some time for me to find the link.
Sure, no more than do I say that than do I google it and get a couple hits on it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.