Check return result from Py_InitModule*(). This API can fail.
Probably should be backported.
diff --git a/Python/import.c b/Python/import.c
index f284ff4..8bd25f7 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2817,6 +2817,8 @@
m = Py_InitModule4("imp", imp_methods, doc_imp,
NULL, PYTHON_API_VERSION);
+ if (m == NULL)
+ goto failure;
d = PyModule_GetDict(m);
if (setint(d, "SEARCH_ERROR", SEARCH_ERROR) < 0) goto failure;
diff --git a/Python/marshal.c b/Python/marshal.c
index ff8247c..5617226 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -1107,5 +1107,7 @@
PyMarshal_Init(void)
{
PyObject *mod = Py_InitModule("marshal", marshal_methods);
+ if (mod == NULL)
+ return;
PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION);
}
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 5bbe950..f793b99 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1027,6 +1027,8 @@
#endif
m = Py_InitModule3("sys", sys_methods, sys_doc);
+ if (m == NULL)
+ return NULL;
sysdict = PyModule_GetDict(m);
{