Skip to content

Commit a5ed2fe

Browse files
bpo-38823: Fix refleaks in faulthandler init error path on Windows (GH-17250)
(cherry picked from commit ac22354) Co-authored-by: Brandt Bucher <[email protected]>
1 parent 829593a commit a5ed2fe

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
@@ -1276,25 +1276,36 @@ PyInit_faulthandler(void)
12761276
#ifdef MS_WINDOWS
12771277
/* RaiseException() codes (prefixed by an underscore) */
12781278
if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION",
1279-
EXCEPTION_ACCESS_VIOLATION))
1280-
return NULL;
1279+
EXCEPTION_ACCESS_VIOLATION)) {
1280+
goto error;
1281+
}
12811282
if (PyModule_AddIntConstant(m, "_EXCEPTION_INT_DIVIDE_BY_ZERO",
1282-
EXCEPTION_INT_DIVIDE_BY_ZERO))
1283-
return NULL;
1283+
EXCEPTION_INT_DIVIDE_BY_ZERO)) {
1284+
goto error;
1285+
}
12841286
if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW",
1285-
EXCEPTION_STACK_OVERFLOW))
1286-
return NULL;
1287+
EXCEPTION_STACK_OVERFLOW)) {
1288+
goto error;
1289+
}
12871290

12881291
/* RaiseException() flags (prefixed by an underscore) */
12891292
if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE",
1290-
EXCEPTION_NONCONTINUABLE))
1291-
return NULL;
1293+
EXCEPTION_NONCONTINUABLE)) {
1294+
goto error;
1295+
}
12921296
if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION",
1293-
EXCEPTION_NONCONTINUABLE_EXCEPTION))
1294-
return NULL;
1297+
EXCEPTION_NONCONTINUABLE_EXCEPTION)) {
1298+
goto error;
1299+
}
12951300
#endif
12961301

12971302
return m;
1303+
1304+
#ifdef MS_WINDOWS
1305+
error:
1306+
Py_DECREF(m);
1307+
return NULL;
1308+
#endif
12981309
}
12991310

13001311
static int

0 commit comments

Comments
 (0)