-
Notifications
You must be signed in to change notification settings - Fork 786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyHANDLE destructor triggers a SystemError #9
Comments
Test case. Original comment by: jorend |
Original comment by: jorend |
Logged In: YES This is a little nasty. I think the PyErr_Clear call is a I've been meaning to move to unittest, and this gave me the Original comment by: mhammond |
Original comment by: mhammond |
Logged In: YES This has been fixed for a while now, and should be in the Original comment by: mhammond |
This code is in PyHANDLE.cpp:
/*static*/ void PyHANDLE::deallocFunc(PyObject *ob)
{
// Call virtual method Close
((PyHANDLE *)ob)->Close();
PyErr_Clear(); // can not leave pending exceptions
in destructors.
delete (PyHANDLE *)ob;
}
If this is called because an unrelated exception
occurred, it incorrectly clears the exception.
For example, suppose I have Python code that calls a
Python function f1(). This function successfully
creates a PyHANDLE, stores it in a local varaible, and
then raises an unrelated exception. The caller, f2(),
catches the exception. At this point, the PyHANDLE
still exists because the traceback object has a
reference to it (indirectly). Now suppose f2() throws
an exception. The previous traceback object is now
released (replaced by the new traceback). The PyHANDLE
object is decref'd and freed. PyHANDLE::deallocFunc()
is called. The exception that f2() threw is now cleared.
This results in a SystemError. The attached test case
reproduces it.
I think it should be
if (!((PyHANDLE *)ob)->Close())
PyErr_Clear();
but I'm not sure.
Reported by: jorend
Original Ticket: "pywin32/bugs/9":https://sourceforge.net/p/pywin32/bugs/9
The text was updated successfully, but these errors were encountered: