bpo-38823: Fix refleak in marshal init error path (GH-17260)
(cherry picked from commit 33b671e72450bf4b5a946ce0dde6b7fe21150108)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
diff --git a/Python/marshal.c b/Python/marshal.c
index b2daff2c..c6a06e8 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -1829,6 +1829,9 @@
PyObject *mod = PyModule_Create(&marshalmodule);
if (mod == NULL)
return NULL;
- PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION);
+ if (PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION) < 0) {
+ Py_DECREF(mod);
+ return NULL;
+ }
return mod;
}