[Python-Dev] funny leak (original) (raw)

Kevin Jacobs jacobs@penguin.theopalgroup.com
Mon, 24 Mar 2003 12:37:18 -0500 (EST)


On Mon, 24 Mar 2003, Michael Hudson wrote:

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:

Your patch isn't a 100% fix, since a reference can still be leaked if the PyDict_SetItem fails. If nobody beats me to it, I can do a validation pass through compile.c and see how many I can squash.

-Kevin

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 = PyDictNew(); for (i = PyListGETSIZE(list); --i >= 0; ) { v = PyIntFromLong(i); if (v == NULL) goto fail; if (PyDictSetItem(d, PyListGETITEM(list, i), v) < 0) goto fail; + PyDECREF(v); if (PyDictDelItem(*cellvars, PyListGETITEM(list, i)) < 0) goto fail; } pos = 0; i = PyListGETSIZE(list); PyDECREF(list); while (PyDictNext(*cellvars, &pos, &v, &w)) { ... found by the obscure strategy of searching for "PyIntFromLong" in Python/compile.c ... A quick eyeballing suggests there are a bunch more of these, but only on error returns. Cheers, M.

--

Kevin Jacobs The OPAL Group - Enterprise Systems Architect Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fax: (216) 986-0714 WWW: http://www.theopalgroup.com