bpo-35454: Fix miscellaneous minor issues in error handling. (GH-11077)
* bpo-35454: Fix miscellaneous minor issues in error handling.
* Fix a null pointer dereference.
(cherry picked from commit 8905fcc85a6fc3ac394bc89b0bbf40897e9497a6)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
diff --git a/Python/import.c b/Python/import.c
index 709fc43..5f5d135 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2138,10 +2138,10 @@
}
mod = _PyImport_FindExtensionObject(name, path);
- if (mod != NULL) {
+ if (mod != NULL || PyErr_Occurred()) {
Py_DECREF(name);
Py_DECREF(path);
- Py_INCREF(mod);
+ Py_XINCREF(mod);
return mod;
}