Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

↑ Back to the top


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.

↑ Back to the top


Resolution

A supported hotfix is 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 software update that contains this hotfix.

If the hotfix is available for download, there is a "Hotfix download available" section at the top of this Knowledge Base article. If this section does not appear, contact Microsoft Customer Service and Support to obtain the hotfix.

Note If additional issues occur or if 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. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft Web site: Note The "Hotfix download available" form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language. 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

↑ Back to the top


Workaround

No workaround exists.

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

↑ Back to the top


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.

↑ Back to the top


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

↑ Back to the top


Keywords: kbautohotfix, kbqfe, kbhotfixserver, kbbug, kbfix, kboracle, KB322968

↑ Back to the top

Article Info
Article ID : 322968
Revision : 10
Created on : 11/15/2007
Published on : 11/15/2007
Exists online : False
Views : 565