[Python-Dev] Small memory leak in unicodeobject.c
Guido van Rossum
guido@python.org
Tue, 03 Oct 2000 13:58:20 -0500
> 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? 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/)