-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-41336: Fix the error handling in zoneinfo_new_instance() #21546
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,8 +224,14 @@ zoneinfo_new_instance(PyTypeObject *type, PyObject *key) | |
self = NULL; | ||
cleanup: | ||
if (file_obj != NULL) { | ||
PyObject *exc, *val, *tb; | ||
PyErr_Fetch(&exc, &val, &tb); | ||
PyObject *tmp = PyObject_CallMethod(file_obj, "close", NULL); | ||
Py_DECREF(tmp); | ||
_PyErr_ChainExceptions(exc, val, tb); | ||
if (tmp == NULL) { | ||
serhiy-storchaka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Py_CLEAR(self); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... this feels a little weird but I suppose it's acceptable. At this point we've actually already succeeded in reading and constructing a Is the idea here that the Ctrl + C here is manifesting as an error in the method call and will only bubble up the stack if we affirmatively raise it here? If so, might it make sense to clear anything derived from |
||
} | ||
Py_XDECREF(tmp); | ||
Py_DECREF(file_obj); | ||
} | ||
Py_DECREF(file_path); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this?
Is the issue that there might be a live exception and that
file_obj.close()
may itself raise an exception, so we want to save the original one and chain it to the new one?