Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Memory Leak in _connectionPtr.open??

Posted on 2004-08-31
5
1,497 Views
Last Modified: 2008-02-07
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?

*****SAMPLE CODE:::

#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)
{
      ::CoInitialize(NULL);

      ADODB::_ConnectionPtr      _cnn;

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

      _cnn->Close();
      _cnn.Release();
      _cnn=NULL;
      ::CoUninitialize();
      return 0;
}

*******OUTPUT FROM PURIFY:

[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;
0
Comment
Question by:nicoleheritage
  • 3
  • 2
5 Comments
 

Author Comment

by:nicoleheritage
ID: 11942017
I am using an ODBC connection to mircosoft Access for testing
0
 
LVL 7

Accepted Solution

by:
jacobhoover earned 500 total points
ID: 11947394
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...
0
 

Author Comment

by:nicoleheritage
ID: 11966808
I agree with your 2 cents and will be heading in that directions.

Thanks,

0
 
LVL 7

Expert Comment

by:jacobhoover
ID: 11968444
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 codeguru.earthweb.com but I remember it taking some time for me to find the link.
0
 
LVL 7

Expert Comment

by:jacobhoover
ID: 11968487
Sure, no more than do I say that than do I google it and get a couple hits on it.

http://www.codeguru.com/Cpp/data/mfc_database/odbc/article.php/c4337/
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 115
How can i compile this github project?? 2 90
Beginner to Unreal Engine 4 5 94
Advice in Xamarin 21 96
This article will show, step by step, how to integrate R code into a R Sweave document
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question