diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-06-11 21:23:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-11 21:23:28 +0200 |
commit | 567d6ae8e77579173510fc948ac06b2ababf3d40 (patch) | |
tree | c85ad7bfb8619b495fbb0c017e1ffeaf8b4ad532 /Python/_warnings.c | |
parent | 3f7c0810f6158a7ff37be432f8d7f9511427489f (diff) | |
download | cpython-567d6ae8e77579173510fc948ac06b2ababf3d40.tar.gz cpython-567d6ae8e77579173510fc948ac06b2ababf3d40.zip |
gh-105375: Improve PyErr_WarnExplicit() error handling (#105610)
Bail on first error to prevent exceptions from possibly being
overwritten.
Diffstat (limited to 'Python/_warnings.c')
-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 69fa04e6bef..465cbf9bd30 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -1298,25 +1298,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; } |