Bug report: memory leak in python 1.5.2

M.-A. Lemburg mal at lemburg.com
Wed May 26 04:05:05 EDT 1999


Greg McFarlane wrote:
> 
> Environment: Solaris 2.5.1, gcc
> 
> The following script chews up cycles (as expected) as well as memory
> (megabytes every few seconds).
> 
> Does anyone know why?
> 
> ======================================================================
> import os
> while 1:
>     os.environ['FOO'] = 'BAR'
> ======================================================================

The code says:

        /* XXX This leaks memory -- not easy to fix :-( */
        if ((new = malloc(strlen(s1) + strlen(s2) + 2)) == NULL)
                return PyErr_NoMemory();
        (void) sprintf(new, "%s=%s", s1, s2);
        if (putenv(new)) {
                posix_error();
                return NULL;
        }

Don't why the free(new); is missing though... maybe some putenv()
implementation expect a malloced string (the putenv implementation
in posixmodule.c for NeXT does) while other make a copy first.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   219 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





More information about the Python-list mailing list