Skip to content

Commit 5bd2af9

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 4ffc569 commit 5bd2af9

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
@@ -1273,25 +1273,36 @@ PyInit_faulthandler(void)
12731273
#ifdef MS_WINDOWS
12741274
/* RaiseException() codes (prefixed by an underscore) */
12751275
if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION",
1276-
EXCEPTION_ACCESS_VIOLATION))
1277-
return NULL;
1276+
EXCEPTION_ACCESS_VIOLATION)) {
1277+
goto error;
1278+
}
12781279
if (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+
}
12811283
if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW",
1282-
EXCEPTION_STACK_OVERFLOW))
1283-
return NULL;
1284+
EXCEPTION_STACK_OVERFLOW)) {
1285+
goto error;
1286+
}
12841287

12851288
/* RaiseException() flags (prefixed by an underscore) */
12861289
if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE",
1287-
EXCEPTION_NONCONTINUABLE))
1288-
return NULL;
1290+
EXCEPTION_NONCONTINUABLE)) {
1291+
goto error;
1292+
}
12891293
if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION",
1290-
EXCEPTION_NONCONTINUABLE_EXCEPTION))
1291-
return NULL;
1294+
EXCEPTION_NONCONTINUABLE_EXCEPTION)) {
1295+
goto error;
1296+
}
12921297
#endif
12931298

12941299
return m;
1300+
1301+
#ifdef MS_WINDOWS
1302+
error:
1303+
Py_DECREF(m);
1304+
return NULL;
1305+
#endif
12951306
}
12961307

12971308
static int

0 commit comments

Comments
 (0)