Microsoft KB Archive/892473

= FIX: You may experience handle leak-like symptoms when you use the _popen CRT function for application development in C++ .NET 2002 =

Article ID: 892473

Article Last Modified on 4/7/2006

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Enterprise Architect

-





SYMPTOMS
You may experience application handle leak-like symptoms when you use the _popen C run-time (CRT) function for application development. This problem occurs in Microsoft Visual C++ .NET 2002.



CAUSE
The CRT library does not close process handles that are opened by the _popen CRT function. This problem causes handle leak-like symptoms and lack of available system resources.



RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft Visual Studio .NET 2002 service pack that contains this hotfix.

To resolve this problem immediately, 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
Visual Studio .NET 2002

Restart requirement
You do not have to restart your computer after you apply this hotfix.

Hotfix replacement information
This hotfix does not replace any other hotfixes.

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. Date        Time   Version        Size    File name -- 08-Jan-2005 03:10                 10,467  Io.h 08-Jan-2005  03:33              2,634,502  Libc.lib 08-Jan-2005 03:37              2,950,432  Libcd.lib 08-Jan-2005 03:34              2,835,448  Libcmt.lib 08-Jan-2005 03:38              3,198,282  Libcmtd.lib 08-Jan-2005 04:24  7.0.9960.0    339,968  Msvcr70.dll 08-Jan-2005 03:39  7.0.9960.0    536,576  Msvcr70d.dll 08-Jan-2005 03:10                 17,411  Popen.c 08-Jan-2005  03:10                  9,959  Read.c 10-Jan-2005  21:46                196,608  Vc_crt.msm 08-Jan-2005 04:24  7.0.9960.0    339,968  Msvcr70.dll



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



Steps to reproduce the problem
 Start Visual Studio .NET 2003. On the File menu, click New, and then click Project. In the New Project window, click the Win32 Visual C++ project type, click the Win32 Console Project template, type in the Name box, type  ://, and then click OK.  In the active code window, replace the generated code with the following code: //repro.c //This is from MSDN. It is a sample of the _popen function. //Use this to verify the handle leak.
 * 1) include &quot;stdafx.h&quot;
 * 2) include &quot;stdio.h&quot;
 * 3) include &quot;stdlib.h&quot;

int main( void ) { int i = 0; for (i = 0; i < 10000; i++) { char psBuffer[128]; FILE *pPipe;

/* Run DIR so that it writes its output to a pipe. Open this if( (pPipe = _popen( &quot;dir *.c /on /p&quot;, &quot;rt&quot; )) == NULL ) exit( 1 );
 * pipe with the read text attribute so that you can read it
 * like a text file.

/* Read the pipe until the end of file. */

while( !feof( pPipe ) ) { if( fgets( psBuffer, 128, pPipe ) != NULL ) printf( psBuffer ); }

/* Close the pipe and print the return value of the pipe. */ { int result = _pclose( pPipe ); printf( &quot;\nProcess returned %d\n&quot;, result); } }

return 0; }  On the Build menu, click Build Solution.</li> On the Debug menu, click Run.</li> Start Windows Task Manager.</li> On the Processes tab, view the Handles for your AppName increment.

Note You may add Handles columns to Windows Task Manager. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> On the View menu, click Select Columns in Windows Task Manager.</li> Click to select the Handle Count check box, and then click OK.</li></ol> </li></ol>

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates

Keywords: kbtshoot kbbug kbfix kbqfe kbvs2002sp1sweep kbhotfixserver KB892473

-

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

© Microsoft Corporation. All rights reserved.