bpo-36854: Fix reference counter in PyInit__testcapi() (GH-17338) · python/cpython@84c36c1

Original file line numberDiff line numberDiff line change

@@ -6283,11 +6283,14 @@ PyInit__testcapi(void)

62836283

PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type);

62846284
62856285

PyModule_AddIntConstant(m, "the_number_three", 3);

6286+

PyObject *v;

62866287

#ifdef WITH_PYMALLOC

6287-

PyModule_AddObject(m, "WITH_PYMALLOC", Py_True);

6288+

v = Py_True;

62886289

#else

6289-

PyModule_AddObject(m, "WITH_PYMALLOC", Py_False);

6290+

v = Py_False;

62906291

#endif

6292+

Py_INCREF(v);

6293+

PyModule_AddObject(m, "WITH_PYMALLOC", v);

62916294
62926295

TestError = PyErr_NewException("_testcapi.error", NULL, NULL);

62936296

Py_INCREF(TestError);