Microsoft KB Archive/322968

= FIX: CColumnsInfo Reference Count Leak in MSDAORA REF CURSOR When You Retrieve Data from an Oracle Function =

Article ID: 322968

Article Last Modified on 11/15/2007

-

APPLIES TO


 * Microsoft OLE DB Provider for Oracle Server 1.0
 * Microsoft Data Access Components 2.7
 * Microsoft Data Access Components 2.7 Service Pack 1
 * Microsoft Data Access Components 2.8

-



This article was previously published under Q322968





SYMPTOMS
When a client application uses the Microsoft OLE DB Provider for Oracle (MSDAORA) that is included with MDAC 2.7, to retrieve data from an Oracle function by using a REF CURSOR, the application leaks memory each time a command is executed to retrieve data from an Oracle function.



CAUSE
The Microsoft OLE DB Provider for Oracle (MSDAORA) incorrectly maintains an extra reference count on the IColumnsInfo wrapper class. This causes a leak each time a new command is executed to retrieve data.



RESOLUTION
A supported hotfix is now available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next service pack that contains this hotfix.

To resolve this problem, submit a request to Microsoft Online Customer Services to obtain the hotfix. To submit an online request to obtain the hotfix, visit the following Microsoft Web site:

http://go.microsoft.com/?linkid=6294451

Note If additional issues occur or any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. To create a separate service request, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

The English version of this hotfix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.

MDAC 2.7
  Date         Time   Version            Size    File name --  22-May-2002  22:03  2.70.8722.0       221,184  Msdaora.dll

MDAC 2.7 SP1
 Date        Time   Version            Size    File name --  05-Mar-2003  18:07  2.71.9031.34      221,184  Msdaora.dll

MDAC 2.8
 Date        Time   Version            Size    File name --  20-Nov-2003  11:55  2.80.1026.0      225,280  Msdaora.dll Note For a list of all the hotfixes available for MDAC 2.8, click the following article number to view the article in the Microsoft Knowledge Base:

839801 FIX: Hotfixes are available for MDAC 2.8



WORKAROUND
No workaround exists.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the problem
 Set up an appropriate Oracle client. In Microsoft Visual C ++ 6.0, create an empty Windows Console Application. Add a new C++ Source file to the project.</li>  Add the following ATL OLE DB client code to the application:
 * 1) define _ATL_STATIC_REGISTRY
 * 2) define _ATL_DEBUG_QI
 * 3) define _ATL_DEBUG_INTERFACES


 * 1) include <atldbcli.h>  // The main ATL consumer header
 * 2) include <conio.h>       // getch
 * 3) include <stdio.h>       // printf

// Second Accessor class CLeakTestAccessor1 { public: DEFINE_COMMAND(CLeakTestAccessor1, _T(&quot;CREATE TABLE TestTable (Int INTEGER, Str VARCHAR2(256));&quot;)) };

// Third Accessor class CLeakTestAccessor2 { public: DEFINE_COMMAND(CLeakTestAccessor2, _T(&quot;INSERT INTO TestTable (Int, Str) VALUES (5, 'This is a test.');&quot;)) };

// Fourth Accessor class CLeakTestAccessor3 { public: DEFINE_COMMAND(CLeakTestAccessor3, _T(&quot;CREATE OR REPLACE PACKAGE Test AS \ TYPE TestCur IS REF CURSOR;\ function LeakTest(p_Num IN INTEGER, p_Cursor OUT TestCur) return integer;\ procedure NoLeakTest(p_Cursor OUT TestCur, p_Num IN INTEGER); \ END Test;&quot;)) };

// Fifth Accessor class CLeakTestAccessor4 { public:

DEFINE_COMMAND(CLeakTestAccessor4, _T(&quot;CREATE OR REPLACE PACKAGE BODY Test AS \ function LeakTest(p_Num IN INTEGER, p_Cursor OUT TestCur) return integer as \ begin \ OPEN p_Cursor FOR \ SELECT Int, Str FROM TestTable; \ return 0; \ end LeakTest;\ procedure NoLeakTest(p_Cursor OUT TestCur, p_Num IN INTEGER) as \ begin \ OPEN p_Cursor FOR \ SELECT Int, Str FROM TestTable; \ end; \ END Test;&quot;)) };

// Initialize the package and create the re-quite table and data HRESULT DoInit {   CDataSource ds; CSession sess; CCommand<CAccessor<CLeakTestAccessor1>,CNoRowset> cmd1; CCommand<CAccessor<CLeakTestAccessor2>,CNoRowset> cmd2; CCommand<CAccessor<CLeakTestAccessor3>,CNoRowset> cmd3; CCommand<CAccessor<CLeakTestAccessor4>,CNoRowset> cmd4; HRESULT hr;

try {       hr = ds.OpenFromInitializationString(L&quot;Provider=MSDAORA.1;Data Source=myServer;Password=myPassword;User ID=myUserID&quot;); hr = sess.Open(ds); ds.Close; hr = cmd1.Open(sess); cmd1.Close; cmd1.ReleaseCommand; cmd1.m_spCommand.Attach(NULL); hr = cmd2.Open(sess); cmd2.Close; cmd2.ReleaseCommand; cmd2.m_spCommand.Attach(NULL); hr = cmd3.Open(sess); cmd3.Close; cmd3.ReleaseCommand; cmd3.m_spCommand.Attach(NULL); hr = cmd4.Open(sess); cmd4.Close; cmd4.ReleaseCommand; cmd4.m_spCommand.Attach(NULL); }   catch(...) {       printf(&quot;\nAn exception has occurred in DoInit...&quot;); AtlTrace(&quot;\nAn exception has occurred in DoInit...&quot;); printf(&quot;\n&quot;); AtlTrace(&quot;\n&quot;); AtlTraceErrorRecords(hr); return E_FAIL; }   return hr; }

// Main Accessor class CLeakTestAccessor { public:

LONG m_RETURNVALUE; LONG m_lNum; LONG m_lInt; TCHAR m_szStr[257];

BEGIN_PARAM_MAP(CLeakTestAccessor) SET_PARAM_TYPE(DBPARAMIO_OUTPUT) COLUMN_ENTRY(1, m_RETURNVALUE) SET_PARAM_TYPE(DBPARAMIO_INPUT) COLUMN_ENTRY(2, m_lNum) END_PARAM_MAP

DEFINE_COMMAND(CLeakTestAccessor, _T(&quot;{ ? = call Test.LeakTest( {resultset 0, p_Cursor},?) }&quot;))

void ClearRecord {       memset(this, 0, sizeof(*this)); }

};

// The main function void main(void) {   HRESULT hr; long lLoopCtr = 0;

try {       // Initialize COM libraries CoInitialize(NULL);

printf(&quot;\nStarting the MSDAORA Leak Test Application...&quot;); AtlTrace(&quot;\nStarting the MSDAORA Leak Test Application...&quot;); // Perform the Initiailization hr = DoInit; if (SUCCEEDED(hr)) {           printf(&quot;\nLooping through 1000 times...&quot;); AtlTrace(&quot;\nLooping through 1000 times...&quot;); for (lLoopCtr =0; lLoopCtr < 1000; lLoopCtr++) {               // Open the Connection CDataSource ds; hr = ds.OpenFromInitializationString(L&quot;Provider=MSDAORA.1;Data Source=myServer;Password=myPassword;User ID=myUserID&quot;); if (SUCCEEDED(hr)) {                   // Open the session CSession sess; hr = sess.Open(ds); for (int i=0; i<1000; i++) {                       if (SUCCEEDED(hr)) {                           CCommand<CAccessor<CLeakTestAccessor> > cmd; cmd.m_lNum = 2; // Open the Command hr = cmd.Open(sess); if (SUCCEEDED(hr)) {                                   hr = cmd.MoveNext; while (hr == S_OK) hr = cmd.MoveNext; } // end if                           cmd.Close; cmd.ReleaseCommand; } // end if                         ds.Close; } // end for } // end if           } // end for }       printf(&quot;Press any key to continue...&quot;); AtlTrace(&quot;Press any key to continue...&quot;); getch; }   catch(...) {       AtlTrace(&quot;\nAn exception has occurred in main...&quot;); printf(&quot;\nAn exception has occurred in main...&quot;); AtlTrace(&quot;\n&quot;); printf(&quot;\n&quot;); AtlTraceErrorRecords(hr); } }

</li> Modify the connection string, the Data Source, the User ID, and the Password parameters as appropriate for your environment.</li> Compile the application.</li> Start Performance Monitor.</li> Run the application. Notice that the Mem Usage counter for this application in Performance Monitor starts to increase.</li> Stop the application.</li> Install the hotfix.</li> Run the application again, and notice that there is no memory leak.</li></ol>

<div class="references_section">