Article ID: 235601 - Last Review: September 6, 2005 - Revision: 3.0

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

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q235601

On This Page

Expand all | Collapse all

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 "=".
    }
}
				

APPLIES TO
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 4.1 Subscription
  • Microsoft Visual C++ 4.2 Enterprise Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 4.2 Professional Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
Keywords: 
kbtshoot kbbug kbfix kbcrt kbnoupdate KB235601