bpo-38823: Fix refleaks in faulthandler init error path on Windows (G… · python/cpython@5bd2af9
@@ -1273,25 +1273,36 @@ PyInit_faulthandler(void)
12731273#ifdef MS_WINDOWS
12741274/* RaiseException() codes (prefixed by an underscore) */
12751275if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION",
1276-EXCEPTION_ACCESS_VIOLATION))
1277-return NULL;
1276+EXCEPTION_ACCESS_VIOLATION)) {
1277+ goto error;
1278+ }
12781279if (PyModule_AddIntConstant(m, "_EXCEPTION_INT_DIVIDE_BY_ZERO",
1279-EXCEPTION_INT_DIVIDE_BY_ZERO))
1280-return NULL;
1280+EXCEPTION_INT_DIVIDE_BY_ZERO)) {
1281+ goto error;
1282+ }
12811283if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW",
1282-EXCEPTION_STACK_OVERFLOW))
1283-return NULL;
1284+EXCEPTION_STACK_OVERFLOW)) {
1285+ goto error;
1286+ }
1284128712851288/* RaiseException() flags (prefixed by an underscore) */
12861289if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE",
1287-EXCEPTION_NONCONTINUABLE))
1288-return NULL;
1290+EXCEPTION_NONCONTINUABLE)) {
1291+ goto error;
1292+ }
12891293if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION",
1290-EXCEPTION_NONCONTINUABLE_EXCEPTION))
1291-return NULL;
1294+EXCEPTION_NONCONTINUABLE_EXCEPTION)) {
1295+ goto error;
1296+ }
12921297#endif
1293129812941299return m;
1300+1301+#ifdef MS_WINDOWS
1302+error:
1303+Py_DECREF(m);
1304+return NULL;
1305+#endif
12951306}
1296130712971308static int