[Python-Dev] funny leak
Michael Hudson
mwh@python.net
Mon, 24 Mar 2003 16:47:34 +0000
Tim Peters <tim.one@comcast.net> writes:
> OK, there's no leaking memory here, but there is a leaking refcount: the
> refcount on the int 0 keeps going up. The compiler has leaked references to
> little integers before, but offhand I don't recall the details.
This seems to be all it takes:
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.275
diff -c -C7 -r2.275 compile.c
*** compile.c 12 Feb 2003 16:56:51 -0000 2.275
--- compile.c 24 Mar 2003 16:43:28 -0000
***************
*** 4524,4537 ****
--- 4564,4578 ----
d = PyDict_New();
for (i = PyList_GET_SIZE(list); --i >= 0; ) {
v = PyInt_FromLong(i);
if (v == NULL)
goto fail;
if (PyDict_SetItem(d, PyList_GET_ITEM(list, i), v) < 0)
goto fail;
+ Py_DECREF(v);
if (PyDict_DelItem(*cellvars, PyList_GET_ITEM(list, i)) < 0)
goto fail;
}
pos = 0;
i = PyList_GET_SIZE(list);
Py_DECREF(list);
while (PyDict_Next(*cellvars, &pos, &v, &w)) {
... found by the obscure strategy of searching for "PyInt_FromLong" in
Python/compile.c ...
A quick eyeballing suggests there are a bunch more of these, but only
on error returns.
Cheers,
M.
--
... when all the programmes on all the channels actually were made
by actors with cleft pallettes speaking lines by dyslexic writers
filmed by blind cameramen instead of merely seeming like that, it
somehow made the whole thing more worthwhile. -- HHGTG, Episode 11