BUG: Putenv() function may cause memory leak when the function is used to remove or to replace an environment variable in Visual C++ (235601)



The information in this article applies to:

  • Microsoft Visual C++ 4.0
  • Microsoft Visual C++ 4.1
  • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 4.2
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q235601

SYMPTOMS

A memory leak results from calls to putenv in the following circumstances:
  • An environment variable is removed.
  • An environment variable is replaced.
  • The input parameter does not contain an equal sign (=) character.

STATUS

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

This problem was corrected in Microsoft Visual C++ .NET.

MORE INFORMATION

Steps to Reproduce Behavior

The following sample code demonstrates the types of calls that will cause a memory leak.

#include <stdlib.h>

void main()
{
    for (;;) {

        putenv( "MYVAR1=mystring" ); // Replaces string MYVAR1
                                     // after first iteration.

        putenv( "MYVAR2=mystring" ); // Creates and removes MYVAR2.
        putenv( "MYVAR2=" );         // 

        putenv( "MYVAR3" );          // Invalid string missing "=".
    }
}
				

Modification Type:MajorLast Reviewed:9/6/2005
Keywords:kbtshoot kbBug kbCRT kbfix kbNoUpdate KB235601 kbAudDeveloper