[Python-checkins] python/dist/src/Python pythonrun.c,2.191,2.192
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Sat, 19 Apr 2003 11:47:04 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv24688/python/Python
Modified Files:
pythonrun.c
Log Message:
handle_system_exit(): This leaked the current exception info, in
particular leaving the traceback object (and everything reachable
from it) alive throughout shutdown. The patch is mostly from Guido.
Bugfix candidate.
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.191
retrieving revision 2.192
diff -C2 -d -r2.191 -r2.192
*** pythonrun.c 19 Apr 2003 15:41:52 -0000 2.191
--- pythonrun.c 19 Apr 2003 18:47:02 -0000 2.192
***************
*** 915,918 ****
--- 915,920 ----
{
PyObject *exception, *value, *tb;
+ int exitcode = 0;
+
PyErr_Fetch(&exception, &value, &tb);
if (Py_FlushLine())
***************
*** 920,924 ****
fflush(stdout);
if (value == NULL || value == Py_None)
! Py_Exit(0);
if (PyInstance_Check(value)) {
/* The error code should be in the `code' attribute. */
--- 922,926 ----
fflush(stdout);
if (value == NULL || value == Py_None)
! goto done;
if (PyInstance_Check(value)) {
/* The error code should be in the `code' attribute. */
***************
*** 928,932 ****
value = code;
if (value == Py_None)
! Py_Exit(0);
}
/* If we failed to dig out the 'code' attribute,
--- 930,934 ----
value = code;
if (value == Py_None)
! goto done;
}
/* If we failed to dig out the 'code' attribute,
***************
*** 934,943 ****
}
if (PyInt_Check(value))
! Py_Exit((int)PyInt_AsLong(value));
else {
PyObject_Print(value, stderr, Py_PRINT_RAW);
PySys_WriteStderr("\n");
! Py_Exit(1);
}
}
--- 936,955 ----
}
if (PyInt_Check(value))
! exitcode = (int)PyInt_AsLong(value);
else {
PyObject_Print(value, stderr, Py_PRINT_RAW);
PySys_WriteStderr("\n");
! exitcode = 1;
}
+ done:
+ /* Restore and clear the exception info, in order to properly decref
+ * the exception, value, and traceback. If we just exit instead,
+ * these leak, which confuses PYTHONDUMPREFS output, and may prevent
+ * some finalizers from running.
+ */
+ PyErr_Restore(exception, value, tb);
+ PyErr_Clear();
+ Py_Exit(exitcode);
+ /* NOTREACHED */
}