FIX: Call to _set_se_translator in DllMain May Cause a Memory Leak (815235)



The information in this article applies to:

  • Microsoft Visual C++
  • The C Run-Time (CRT)
  • Microsoft Visual Studio, Enterprise Edition 6.0
  • Microsoft Visual Studio 6.0 SP5
  • the operating system: Microsoft Windows NT 4.0
  • the operating system: Microsoft Windows NT 4.0 SP1
  • the operating system: Microsoft Windows NT 4.0 SP2
  • the operating system: Microsoft Windows NT 4.0 SP3
  • the operating system: Microsoft Windows NT 4.0 SP4
  • the operating system: Microsoft Windows NT 4.0 SP5
  • the operating system: Microsoft Windows NT 4.0 SP6
  • the operating system: Microsoft Windows NT 4.0 SP6a

SYMPTOMS

In a multithreaded application, if a DLL's DllMain makes a call to _set_se_translator, you may experience a memory leak in the CRT.

CAUSE

This problem occurs if you used the _beginthreadex API to create the thread because the initialization order in the CRT causes the per thread data (PTD) structure for the thread to be allocated two times.

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.

Note You must have a Visual Studio license agreement to obtain this hotfix.

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: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 fix 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.
   Date         Time   Version     Size       File name
   ------------------------------------------------------
   22-Feb-2003  04:42              3,218,510  Libcmtd.lib
   22-Feb-2003  04:46  6.0.9748.0    434,252  Msvcrtd.dll
   22-Feb-2003  04:33                934,378  Libcmt.lib
   22-Feb-2003  05:45  6.0.9748.0    278,581  Msvcrt.dll
   22-Feb-2003  03:42                  6,615  Thread.c
   22-Feb-2003  03:42                  8,554  Threadex.c

WORKAROUND

You can avoid this problem by calling _set_se_translator at the beginning of your thread procedure instead of in DllMain. It is not a good idea to call CRT functions such as _set_se_translator in DllMain.
You can also work around the problem by using CreateThread instead of _beginthreadex to start your threads.

STATUS


Modification Type:MinorLast Reviewed:10/21/2005
Keywords:kbpending kbbug KB815235