diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-11 19:51:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-11 19:51:30 (GMT) |
commit | db5022c16f94622285eda5f036450e34f5f415ce (patch) | |
tree | 5f670e93b0e03b74cc7e43854d29b829f0001cbb /Python | |
parent | c14f6ea7e44790d0518c3a0c17b8b1336f3a1602 (diff) | |
download | cpython-db5022c16f94622285eda5f036450e34f5f415ce.zip cpython-db5022c16f94622285eda5f036450e34f5f415ce.tar.gz cpython-db5022c16f94622285eda5f036450e34f5f415ce.tar.bz2 |
[3.12] gh-105375: Improve PyErr_WarnExplicit() error handling (GH-105610) (#105659)
Bail on first error to prevent exceptions from possibly being
overwritten.
(cherry picked from commit 567d6ae8e77579173510fc948ac06b2ababf3d40)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/_warnings.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index dec6586..1f91edb 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -1301,25 +1301,29 @@ PyErr_WarnExplicit(PyObject *category, const char *text, const char *module_str, PyObject *registry) { PyObject *message = PyUnicode_FromString(text); + if (message == NULL) { + return -1; + } PyObject *filename = PyUnicode_DecodeFSDefault(filename_str); + if (filename == NULL) { + Py_DECREF(message); + return -1; + } PyObject *module = NULL; - int ret = -1; - - if (message == NULL || filename == NULL) - goto exit; if (module_str != NULL) { module = PyUnicode_FromString(module_str); - if (module == NULL) - goto exit; + if (module == NULL) { + Py_DECREF(filename); + Py_DECREF(message); + return -1; + } } - ret = PyErr_WarnExplicitObject(category, message, filename, lineno, - module, registry); - - exit: - Py_XDECREF(message); + int ret = PyErr_WarnExplicitObject(category, message, filename, lineno, + module, registry); Py_XDECREF(module); - Py_XDECREF(filename); + Py_DECREF(filename); + Py_DECREF(message); return ret; } |