[Python-checkins] bpo-38823: Fix refleaks in faulthandler init error path on Windows (GH-17250)

Victor Stinner webhook-mailer at python.org
Tue Nov 19 18:13:10 EST 2019


https://github.com/python/cpython/commit/ac2235432c607ce2c0faf6dff5d9b2534d2f6652
commit: ac2235432c607ce2c0faf6dff5d9b2534d2f6652
branch: master
author: Brandt Bucher <brandtbucher at gmail.com>
committer: Victor Stinner <vstinner at python.org>
date: 2019-11-20T00:13:05+01:00
summary:

bpo-38823: Fix refleaks in faulthandler init error path on Windows (GH-17250)

files:
M Modules/faulthandler.c

diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index 129a104dba3f3..d1280532ae2d4 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -1334,25 +1334,36 @@ PyInit_faulthandler(void)
 #ifdef MS_WINDOWS
     /* RaiseException() codes (prefixed by an underscore) */
     if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION",
-                                EXCEPTION_ACCESS_VIOLATION))
-        return NULL;
+                                EXCEPTION_ACCESS_VIOLATION)) {
+        goto error;
+    }
     if (PyModule_AddIntConstant(m, "_EXCEPTION_INT_DIVIDE_BY_ZERO",
-                                EXCEPTION_INT_DIVIDE_BY_ZERO))
-        return NULL;
+                                EXCEPTION_INT_DIVIDE_BY_ZERO)) {
+        goto error;
+    }
     if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW",
-                                EXCEPTION_STACK_OVERFLOW))
-        return NULL;
+                                EXCEPTION_STACK_OVERFLOW)) {
+        goto error;
+    }
 
     /* RaiseException() flags (prefixed by an underscore) */
     if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE",
-                                EXCEPTION_NONCONTINUABLE))
-        return NULL;
+                                EXCEPTION_NONCONTINUABLE)) {
+        goto error;
+    }
     if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION",
-                                EXCEPTION_NONCONTINUABLE_EXCEPTION))
-        return NULL;
+                                EXCEPTION_NONCONTINUABLE_EXCEPTION)) {
+        goto error;
+    }
 #endif
 
     return m;
+
+#ifdef MS_WINDOWS
+error:
+    Py_DECREF(m);
+    return NULL;
+#endif
 }
 
 static int



More information about the Python-checkins mailing list