FIX: Thread Local Storage Leak Under Internet Explorer 3.0x

ID: Q194707


The information in this article applies to:
  • Microsoft Internet Explorer (Programming) versions 3.0, 3.01, 3.02


SYMPTOMS

Repeated loading and unloading of the Wininet.dll library from a single process will eventually fail. After approximately 63 loading and unloading of the library, the process will no longer be able to load the Wininet.dll library.

This problem can also be seen with COM objects linked statically to Wininet.dll. If within a single process, the COM object is instatiated and destroyed many times, eventually the CoCreateInstance() call to the COM object will fail.


CAUSE

Wininet.dll library requires the use of a Thread Local Storage when loaded. However, when a FreeLibrary() call is made, the Wininet.dll fails to release the TLS it used. Consequently, the process will eventually run out of TLSs causing any future LoadLibrary() calls to fail.


RESOLUTION

At this time, there are two workarounds:

  • Upgrade the system to Internet Explorer 4.x. Internet Explorer 4.x's Wininet.dll does not exhibit this behavior.


  • Avoid dynamically loading and unloading the Wininet.dll from your process.



STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Microsoft Internet Explorer 5.


MORE INFORMATION

Steps to Reproduce Behavior

Building and running the following piece of code under a system using Internet Explorer 3.0x will demonstrate this bug:


#include <windows.h>
#include <stdio.h>

int main ()
{
   HINSTANCE hInst;
   int counter = 0;

   while (1)
   {
      if (!(hInst = LoadLibrary ("wininet.dll")))
      {
         printf("LoadLibrary failed : %d \t Counter : %d\r\n",
            GetLastError(), counter);
         break;
      }

      if (!FreeLibrary (hInst))
      {
         printf("FreeLibrary failed : %d \t Counter : %d\r\n",
            GetLastError(), counter);
         break;
      }

      counter++;
   }

    return 0;

} 

Additional query words:

Keywords : kbIE300bug kbIE301bug kbIE302bug kbIE500fix
Version : WINDOWS:3.0,3.01,3.02
Platform :
Issue type : kbbug


Last Reviewed: April 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.