Skip to content

Commit ac22354

Browse files
brandtbuchervstinner
authored andcommitted
bpo-38823: Fix refleaks in faulthandler init error path on Windows (GH-17250)
1 parent 293dd23 commit ac22354

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

Modules/faulthandler.c

+21-10
Original file line numberDiff line numberDiff line change
@@ -1334,25 +1334,36 @@ PyInit_faulthandler(void)
13341334
#ifdef MS_WINDOWS
13351335
/* RaiseException() codes (prefixed by an underscore) */
13361336
if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION",
1337-
EXCEPTION_ACCESS_VIOLATION))
1338-
return NULL;
1337+
EXCEPTION_ACCESS_VIOLATION)) {
1338+
goto error;
1339+
}
13391340
if (PyModule_AddIntConstant(m, "_EXCEPTION_INT_DIVIDE_BY_ZERO",
1340-
EXCEPTION_INT_DIVIDE_BY_ZERO))
1341-
return NULL;
1341+
EXCEPTION_INT_DIVIDE_BY_ZERO)) {
1342+
goto error;
1343+
}
13421344
if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW",
1343-
EXCEPTION_STACK_OVERFLOW))
1344-
return NULL;
1345+
EXCEPTION_STACK_OVERFLOW)) {
1346+
goto error;
1347+
}
13451348

13461349
/* RaiseException() flags (prefixed by an underscore) */
13471350
if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE",
1348-
EXCEPTION_NONCONTINUABLE))
1349-
return NULL;
1351+
EXCEPTION_NONCONTINUABLE)) {
1352+
goto error;
1353+
}
13501354
if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION",
1351-
EXCEPTION_NONCONTINUABLE_EXCEPTION))
1352-
return NULL;
1355+
EXCEPTION_NONCONTINUABLE_EXCEPTION)) {
1356+
goto error;
1357+
}
13531358
#endif
13541359

13551360
return m;
1361+
1362+
#ifdef MS_WINDOWS
1363+
error:
1364+
Py_DECREF(m);
1365+
return NULL;
1366+
#endif
13561367
}
13571368

13581369
static int

0 commit comments

Comments
 (0)