[Python-bugs-list] [ python-Bugs-675259 ] os.environ leaks under FreeBSD and Mac OS X

SourceForge.net noreply@sourceforge.net
Thu, 06 Feb 2003 17:45:25 -0800


Bugs item #675259, was opened at 2003-01-27 16:39
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=675259&group_id=5470

Category: Documentation
Group: Platform-specific
Status: Open
Resolution: None
Priority: 5
Submitted By: Stuart Bishop (zenzen)
Assigned to: Nobody/Anonymous (nobody)
Summary: os.environ leaks under FreeBSD and Mac OS X

Initial Comment:
If this sort if thing is documented anywhere, the putenv(3) method leaks under FreeBSD and Mac OS X (Mac OS X documents it as a bug they inherited from the FreeBSD codebase in the man page).

So don't set environment variables in a loop.

----------------------------------------------------------------------

>Comment By: Stuart Bishop (zenzen)
Date: 2003-02-07 12:45

Message:
Logged In: YES 
user_id=46639

The following code will demonstrate the issue under Mac OS X
(measured using 'top'). I havn't got access to a FreeBSD system 
to test it on. 

Python 2.3a1 (#1, Jan 30 2003, 16:43:39) 
[GCC 3.1 20020420 (prerelease)] on darwin
Type "help", "copyright", "credits" or "license" for more
information.
>>> import os
>>> while 1:
...     for e in ['some','strings','of','different','length']:
...             os.environ['TZ'] = e
...             del os.environ['TZ']
... 


Removing the 'del os.environ['TZ'] line makes no difference.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-02-07 12:28

Message:
Logged In: YES 
user_id=33168

Stuart have you tested this or are you just assuming that
putenv leaks in python?  I tested this on FreeBSD and the
process did not leak.  Note that python maintains a
dictionary of all the values set with putenv, if they are
set again, the memory will be cleared.  See posix_putenv()
in posixmodule.c and the posix_putenv_garbage variable.

----------------------------------------------------------------------

Comment By: Stuart Bishop (zenzen)
Date: 2003-01-29 11:15

Message:
Logged In: YES 
user_id=46639

Relevant URL's:

http://www.freebsd.org/cgi/query-pr.cgi?pr=misc/19406
http://www.freebsd.org/cgi/query-pr.cgi?pr=10341
http://www.freebsd.org/cgi/query-pr.cgi?pr=5604

An alternative may be to bypass the putenv(3) method on these platforms
and manipulate environ manually in which case this is not a documentation bug but a feature request.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=675259&group_id=5470