[Python-Dev] Re: [Python-checkins] CVS: python/dist/src/Python ceval.c,2.250,2.251

Neil Schemenauer nas@python.ca
Wed, 20 Jun 2001 07:28:20 -0700


Tim Peters wrote:
> gen_iternext():  repair subtle refcount problem.
> NeilS, please check!  This came from staring at your genbug.py, but I'm
> not sure it plugs all possible holes.  Without this, I caught a
> frameobject refcount going negative, and it was also the cause (in debug
> build) of _Py_ForgetReference's attempt to forget an object with already-
> NULL _ob_prev and _ob_next pointers -- although I'm still not entirely
> sure how!

Doesn't this cause a memory leak?  f_back is INCREFed in
PyFrame_New.  There are other problems lurking here as well.

    def f():
        try:
            yield 1
        finally:
            print "finally"

    def h():
        g = f()
        g.next()

    while 1:
        h()

The above code leaks memory like mad, with or without your
change.  Also, the finally clause is never executed although it
probably should be.  My feeling is that the reference counting of
f_back should be done by ceval and not by the frame object.  The
problem with the finally clause is another ball of wax.  I think
its fixable though.

I'll look at it closer this evening.

  Neil