From 4e91aa6ff9b1a04e4a78eb01d487a3d46213b12a Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Mon, 18 Nov 2019 22:58:10 -0800 Subject: [PATCH 1/3] Clean up refleaks in module initialization. --- Modules/faulthandler.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 129a104dba3f33..f058413206d713 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1334,22 +1334,32 @@ PyInit_faulthandler(void) #ifdef MS_WINDOWS /* RaiseException() codes (prefixed by an underscore) */ if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION", - EXCEPTION_ACCESS_VIOLATION)) + EXCEPTION_ACCESS_VIOLATION)) { + Py_DECREF(m); return NULL; + } if (PyModule_AddIntConstant(m, "_EXCEPTION_INT_DIVIDE_BY_ZERO", - EXCEPTION_INT_DIVIDE_BY_ZERO)) + EXCEPTION_INT_DIVIDE_BY_ZERO)) { + Py_DECREF(m); return NULL; + } if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW", - EXCEPTION_STACK_OVERFLOW)) + EXCEPTION_STACK_OVERFLOW)) { + Py_DECREF(m); return NULL; + } /* RaiseException() flags (prefixed by an underscore) */ if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE", - EXCEPTION_NONCONTINUABLE)) + EXCEPTION_NONCONTINUABLE)) { + Py_DECREF(m); return NULL; + } if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION", - EXCEPTION_NONCONTINUABLE_EXCEPTION)) + EXCEPTION_NONCONTINUABLE_EXCEPTION)) { + Py_DECREF(m); return NULL; + } #endif return m; From a0af66d5f5b535d250c326a17f366a2f299767c9 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Tue, 19 Nov 2019 13:52:36 -0800 Subject: [PATCH 2/3] Use a labeled failure branch. --- Modules/faulthandler.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index f058413206d713..155fecafe324b9 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1335,34 +1335,33 @@ PyInit_faulthandler(void) /* RaiseException() codes (prefixed by an underscore) */ if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION", EXCEPTION_ACCESS_VIOLATION)) { - Py_DECREF(m); - return NULL; + goto error; } if (PyModule_AddIntConstant(m, "_EXCEPTION_INT_DIVIDE_BY_ZERO", EXCEPTION_INT_DIVIDE_BY_ZERO)) { - Py_DECREF(m); - return NULL; + goto error; } if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW", EXCEPTION_STACK_OVERFLOW)) { - Py_DECREF(m); - return NULL; + goto error; } /* RaiseException() flags (prefixed by an underscore) */ if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE", EXCEPTION_NONCONTINUABLE)) { - Py_DECREF(m); - return NULL; + goto error; } if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION", EXCEPTION_NONCONTINUABLE_EXCEPTION)) { - Py_DECREF(m); - return NULL; + goto error; } #endif return m; + +error: + Py_DECREF(m); + return NULL; } static int From 46f8a0cf2e859de684a78a555422ef67a96ef8de Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Tue, 19 Nov 2019 14:31:41 -0800 Subject: [PATCH 3/3] Guard unused label. --- Modules/faulthandler.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 155fecafe324b9..d1280532ae2d4d 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1359,9 +1359,11 @@ PyInit_faulthandler(void) return m; +#ifdef MS_WINDOWS error: Py_DECREF(m); return NULL; +#endif } static int