BUG: Putenv() Function Causes Memory Leak

ID: Q235601


The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1, 4.2, 5.0, 6.0


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 this to be a bug in the Microsoft products listed at the beginning of this article.


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

Additional query words: kbvc400

Keywords : kbCRT kbVC500bug kbVC600bug kbDSupport kbGrpVCCompiler
Version : winnt:4.0,4.1,4.2,5.0,6.0
Platform : winnt
Issue type : kbbug


Last Reviewed: July 12, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.