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 84c36c152a)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2019-11-22 04:56:59 -08:00 committed by GitHub
parent 91c15a542c
commit bff5255664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

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