Microsoft KB Archive/139071

= FIX: OLE Automation BSTR caching will cause memory leak sources in Windows 2000 =

Article ID: 139071

Article Last Modified on 7/26/2006

-

APPLIES TO


 * Microsoft Windows 2000 Professional Edition
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Advanced Server

-



This article was previously published under Q139071





SUMMARY
This article describes the following about this hotfix release:
 * The issues that are fixed by the hotfix package.
 * The prerequisites that are required to install the hotfix package.
 * Whether you must restart the computer after you install the hotfix package.
 * Whether the hotfix package is replaced by any other hotfix package.
 * Whether you must make any registry changes.
 * The files that are contained in the hotfix package.



SYMPTOMS
Automation (previously called OLE Automation and ActiveX Automation) caches the space allocated for BSTR strings. This may cause IMallocSpy to attribute memory leaks to the wrong BSTR user in an application that uses Automation's BSTR strings. The correct source of the leak can be found by disabling Automation's cache by setting the environment variable OANOCACHE=1 before running the application. In many server-based applications, the BSTR cache is not required. There is a hotfix available to disable BSTR caching on Windows 2000 computers. Windows XP and Windows Server 2003 do not require the hotfix to disable BSTR caching.



RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that this article describes. Apply it only to systems that are experiencing this specific problem.

To resolve this problem, 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:

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

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.

Prerequisites
You must have installed Windows 2000 Service Pack 4 (SP4) to apply this hotfix.

Restart information
You must restart the computer after you apply this hotfix.

Registry information
You do not have to change the registry.

Hotfix file information
This hotfix contains only those files that are required to correct the issues that this article lists. This hotfix may not contain of all the files that you must have to fully update a product to the latest build. The English version of this hotfix has the file attributes (or later file attributes) 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.



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



MORE INFORMATION
Automation caches the space allocated for BSTRs. This speeds up the SysAllocString/SysFreeString sequence. However, this may cause IMallocSpy to attribute leaks to the wrong memory user because it is not aware of the caching that Automation performs. For example, if the application allocates a BSTR and frees it, the freed block of memory is put into the BSTR cache by Automation. If the application then allocates another BSTR, it may receive the free block from the cache. If the second BSTR allocation is not freed, IMallocSpy will attribute the leak to the first allocation of the BSTR. The correct leak source (the second allocation) can be determined by disabling the BSTR caching that Automation performs. You can do this by setting environment variable OANOCACHE=1 before you run the application. On Windows 2000, the hotfix version of oleaut32.dll referenced in this article is required. It is also important to look for leaks at the correct time to prevent false leak reports. These leaks may occur when the IMallocSpy implementation checks for leaks too soon. Users of memory that is allocated by IMalloc can legitimately hold on to it after OleUninitialize. For example, the Automation BSTR cache is deleted at the Oleaut32.dll file's DLL_PROCESS_DETACH time. This means that checking for leaks immediately after OleUninitialize may cause false reports of memory leaks. A good place to look for memory leaks is in the destructor of a static instance of a class, that implements IMallocSpy. The destructor of this static instance is called after the DllMain of each DLL linked by the application is called with DLL_PROCESS_DETACH.

Set the OANOCACHE environment variable

 * 1) In Control Panel, double-click the System icon. The System Properties dialog box appears.
 * 2) On the Advanced tab, click Environment Variables. The Environment Variables dialog box appears.
 * 3) Under System variables, click New. The New System Variable dialog box appears.
 * 4) Type OANOCACHE in the Variable Name box.
 * 5) Type 1 in the Variable Value box.
 * 6) Click OK three times.

Before you change the OANOCACHE environment variable, you must stop the following server processes if they are running:
 * The Inetinfo process
 * The Dllhost process
 * The W3wp process
 * The Aspnet_wp process

Note If you are not sure whether these server processes are running, set the environment variable OANOCACHE=1, and then restart the computer.

