diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-06-09 20:36:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-09 20:36:53 (GMT) |
commit | e0087df65df485478401aec321b22e2f92407cd3 (patch) | |
tree | ec4f14f42628fbb8d263ba38160745e8dddcabaf /Modules | |
parent | 04b76ece7f92bd7e46ca2f3b46e7a42cfd75fa05 (diff) | |
download | cpython-e0087df65df485478401aec321b22e2f92407cd3.zip cpython-e0087df65df485478401aec321b22e2f92407cd3.tar.gz cpython-e0087df65df485478401aec321b22e2f92407cd3.tar.bz2 |
[3.12] gh-105375: Improve errnomodule error handling (#105590) (#105596)
(cherry picked from commit eede1d2f48b4fe7f7918952d9ebeb744b58668c1)
Bail immediately if an exception is set, to prevent exceptions from
being overwritten.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/errnomodule.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c index fddde96..301ad83 100644 --- a/Modules/errnomodule.c +++ b/Modules/errnomodule.c @@ -81,9 +81,12 @@ end: static int errno_exec(PyObject *module) { - PyObject *module_dict = PyModule_GetDict(module); + PyObject *module_dict = PyModule_GetDict(module); // Borrowed ref. + if (module_dict == NULL) { + return -1; + } PyObject *error_dict = PyDict_New(); - if (!module_dict || !error_dict) { + if (error_dict == NULL) { return -1; } if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) { |