]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36854: Fix reference counter in PyInit__testcapi() (GH-17338)
authorVictor Stinner <vstinner@python.org>
Fri, 22 Nov 2019 12:39:36 +0000 (13:39 +0100)
committerGitHub <noreply@github.com>
Fri, 22 Nov 2019 12:39:36 +0000 (13:39 +0100)
Increment properly Py_True/Py_False reference counter for
_testcapi.WITH_PYMALLOC variable.

Modules/_testcapimodule.c

index 46d772cff608e2a886c344c65e1c070d8fed1766..b54071669cf9972c64def3238519be576dcc35e5 100644 (file)
@@ -6283,11 +6283,14 @@ PyInit__testcapi(void)
     PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type);
 
     PyModule_AddIntConstant(m, "the_number_three", 3);
+    PyObject *v;
 #ifdef WITH_PYMALLOC
-    PyModule_AddObject(m, "WITH_PYMALLOC", Py_True);
+    v = Py_True;
 #else
-    PyModule_AddObject(m, "WITH_PYMALLOC", Py_False);
+    v = Py_False;
 #endif
+    Py_INCREF(v);
+    PyModule_AddObject(m, "WITH_PYMALLOC", v);
 
     TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
     Py_INCREF(TestError);