From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 22 Nov 2019 12:56:59 +0000 (-0800) Subject: bpo-36854: Fix reference counter in PyInit__testcapi() (GH-17338) X-Git-Tag: v3.7.6rc1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bff525566469021949910deec84e837306b79886;p=thirdparty%2FPython%2Fcpython.git bpo-36854: Fix reference counter in PyInit__testcapi() (GH-17338) Increment properly Py_True/Py_False reference counter for _testcapi.WITH_PYMALLOC variable. (cherry picked from commit 84c36c152a2bdf98f9cc7ce0e1db98e1f442a05e) Co-authored-by: Victor Stinner --- diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 64b7b6904939..16ea9c2d6655 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -5444,11 +5444,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);