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



The information in this article applies to:

  • Microsoft OLE DB Provider for Oracle 2.7
  • Microsoft Data Access Components 2.7
  • Microsoft Data Access Components 2.7 SP1
  • 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, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next MDAC 2.7 SP2 that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question. 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 "Applies to" section.

MORE INFORMATION

Steps to reproduce the problem

  1. Set up an appropriate Oracle client.
  2. In Microsoft Visual C ++ 6.0, create an empty Windows Console Application.
  3. Add a new C++ Source file to the project.
  4. Add the following ATL OLE DB client code to the application:
    #define _ATL_STATIC_REGISTRY 
    #define _ATL_DEBUG_QI   
    #define _ATL_DEBUG_INTERFACES
    
    #include <atldbcli.h>   // The main ATL consumer header
    #include <conio.h>		// getch()
    #include <stdio.h>		// printf()
    
    // Second Accessor
    class CLeakTestAccessor1
    {
    public:
    	DEFINE_COMMAND(CLeakTestAccessor1, _T("CREATE TABLE TestTable (Int INTEGER, Str VARCHAR2(256));"))
    };
    
    // Third Accessor
    class CLeakTestAccessor2
    {
    public:
    	DEFINE_COMMAND(CLeakTestAccessor2, _T("INSERT INTO TestTable (Int, Str) VALUES (5, 'This is a test.');"))
    };
    
    // Fourth Accessor
    class CLeakTestAccessor3
    {
    public:
    	DEFINE_COMMAND(CLeakTestAccessor3, _T("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;"))
    };
    
    // Fifth Accessor
    class CLeakTestAccessor4
    {
    public:
    
    	DEFINE_COMMAND(CLeakTestAccessor4, _T("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;"))
    };
    
    // 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"Provider=MSDAORA.1;Data Source=myServer;Password=myPassword;User ID=myUserID");
    		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("\nAn exception has occurred in DoInit()...");
    		AtlTrace("\nAn exception has occurred in DoInit()...");
    		printf("\n");
    		AtlTrace("\n");
    		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("{ ? = call Test.LeakTest( {resultset 0, p_Cursor},?) }"))
    
    	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("\nStarting the MSDAORA Leak Test Application...");
    		AtlTrace("\nStarting the MSDAORA Leak Test Application...");
    		// Perform the Initiailization
    		hr = DoInit();
    		if (SUCCEEDED(hr))
    		{
    			printf("\nLooping through 1000 times...");
    			AtlTrace("\nLooping through 1000 times...");
    			for (lLoopCtr =0; lLoopCtr < 1000; lLoopCtr++)
    			{
    				// Open the Connection
    				CDataSource ds;
    				hr = ds.OpenFromInitializationString(L"Provider=MSDAORA.1;Data Source=myServer;Password=myPassword;User ID=myUserID");
    				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("Press any key to continue...");
    		AtlTrace("Press any key to continue...");
    		getch();
    	}
    	catch(...)
    	{
    		AtlTrace("\nAn exception has occurred in main()...");
    		printf("\nAn exception has occurred in main()...");
    		AtlTrace("\n");
    		printf("\n");
    		AtlTraceErrorRecords(hr);
    	}
    }
    
     
    						
  5. Modify the connection string, the Data Source, the User ID, and the Password parameters as appropriate for your environment.
  6. Compile the application.
  7. Start Performance Monitor.
  8. Run the application. Notice that the Mem Usage counter for this application in Performance Monitor starts to increase.
  9. Stop the application.
  10. Install the hotfix.
  11. Run the application again, and notice that there is no memory leak.

REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

815701 FIX: Memory leak may occur in Microsoft OLE DB Provider for Oracle when you use the REF CURSOR data type and the LONG data type


Modification Type:MajorLast Reviewed:4/7/2006
Keywords:kbQFE KBHotfixServer kbbug kbfix kbOracle KB322968 kbAudDeveloper