diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-11 19:46:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-11 19:46:02 (GMT) |
commit | 05c73e1cd872843952f0e769265ec3d9535488f6 (patch) | |
tree | 4af1029204152e7a5f2a2b5aa9f00d6c0e5f744a /Python | |
parent | 87e493b11a6791777303ba6eda4027df99b7ffcb (diff) | |
download | cpython-05c73e1cd872843952f0e769265ec3d9535488f6.zip cpython-05c73e1cd872843952f0e769265ec3d9535488f6.tar.gz cpython-05c73e1cd872843952f0e769265ec3d9535488f6.tar.bz2 |
[3.11] gh-105375: Improve PyErr_WarnExplicit() error handling (GH-105610) (#105660)
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 4e22400..2815f79 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -1231,25 +1231,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; } |