[Python-Dev] Small memory leak in unicodeobject.c

M.-A. Lemburg mal@lemburg.com
Tue, 03 Oct 2000 20:02:39 +0200


Guido van Rossum wrote:
> 
> > Index: unicodeobject.c
> > ===================================================================
> > RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
> > retrieving revision 2.64
> > diff -u -r2.64 unicodeobject.c
> > --- unicodeobject.c   2000/09/26 05:46:01     2.64
> > +++ unicodeobject.c   2000/10/03 16:31:32
> > @@ -5234,7 +5234,11 @@
> >       PyObject_DEL(v);
> >      }
> >      unicode_freelist = NULL;
> > -    unicode_freelist_size = 0;
> > +    /* XXX This is a hack to force the freeing of unicode_empty's memory.
> > +     * Otherwise, it'll get placed on the already freed free list.
> > +     */
> > +    unicode_freelist_size = MAX_UNICODE_FREELIST_SIZE;
> >      Py_XDECREF(unicode_empty);
> >      unicode_empty = NULL;
> > +    unicode_freelist_size = 0;
> >  }
> 
> Doesn't it make more sense to decref unicode_empty sooner? 

Right. That's the change I proposed to Barry in my last mail.
Please check this in.

Thanks,
Marc-Andre

> The loop
> over the free list won't touch it:
> 
> Index: unicodeobject.c
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
> retrieving revision 2.64
> diff -c -r2.64 unicodeobject.c
> *** unicodeobject.c     2000/09/26 05:46:01     2.64
> --- unicodeobject.c     2000/10/03 17:55:34
> ***************
> *** 5225,5230 ****
> --- 5225,5232 ----
>   {
>       PyUnicodeObject *u = unicode_freelist;
> 
> +     Py_XDECREF(unicode_empty);
> +     unicode_empty = NULL;
>       while (u != NULL) {
>         PyUnicodeObject *v = u;
>         u = *(PyUnicodeObject **)u;
> ***************
> *** 5235,5240 ****
>       }
>       unicode_freelist = NULL;
>       unicode_freelist_size = 0;
> -     Py_XDECREF(unicode_empty);
> -     unicode_empty = NULL;
>   }
> --- 5237,5240 ----
> 
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> 
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> http://www.python.org/mailman/listinfo/python-dev

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