Microsoft KB Archive/815235

= FIX: Call to _set_se_translator in DllMain May Cause a Memory Leak =

Article ID: 815235

Article Last Modified on 10/21/2005

-

APPLIES TO


 * Microsoft Visual C++ 6.1
 * The C Run-Time (CRT)
 * Microsoft Visual Studio 6.0 Enterprise Edition
 * Microsoft Visual Studio 6.0 Service Pack 5
 * Microsoft Windows NT 4.0
 * Microsoft Windows NT 4.0 Service Pack 1
 * Microsoft Windows NT 4.0 Service Pack 2
 * Microsoft Windows NT 4.0 Service Pack 3
 * Microsoft Windows NT 4.0 Service Pack 4
 * Microsoft Windows NT 4.0 Service Pack 5
 * Microsoft Windows NT 4.0 Service Pack 6
 * Microsoft Windows NT 4.0 Service Pack 6a

-



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:

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. 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
Keywords: kbbug kbpending KB815235

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.