[Python-bugs-list] [ python-Bugs-529750 ] Circular reference makes Py_Init crash

noreply@sourceforge.net noreply@sourceforge.net
Wed, 13 Mar 2002 20:52:34 -0800


Bugs item #529750, was opened at 2002-03-13 23:52
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=529750&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Adam M. Fass (afass)
Assigned to: Nobody/Anonymous (nobody)
Summary: Circular reference makes Py_Init crash

Initial Comment:
Call Py_Initialize(), create two objects that 
reference each other, then call Py_Finalize() and 
then Py_Intialize() again.  This crashes Python with 
the following error message:

Fatal Python error: UNREF invalid object

The documentation on Py_Finalize() mentions that 
circular references will cause memory leaks, but it 
does not mention this behavior.

Platform info:
* Windows XP
* Visual C++ 6.0
* Python 2.2

------------------------------

#include "Python.h"

int main(int argc, char* argv[])
{
	char *code1 = "class TestClass:\n\ti = 3\nt1 
= TestClass()\nt2 = TestClass()\nt1.t = t2\nt2.t = 
t1";
	Py_Initialize();

	PyRun_SimpleString(code1);

	Py_Finalize();

	Py_Initialize();
	Py_Finalize();
}

------------------------------

The string "code1" contains this python code:

class TestClass:
   i = 3
t1 = TestClass()
t2 = TestClass()
t1.t = t2
t2.t = t1

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=529750&group_id=5470