Skip to content

Commit 84c36c1

Browse files
authored
bpo-36854: Fix reference counter in PyInit__testcapi() (GH-17338)
Increment properly Py_True/Py_False reference counter for _testcapi.WITH_PYMALLOC variable.
1 parent 107ed88 commit 84c36c1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Modules/_testcapimodule.c

Lines changed: 5 additions & 2 deletions
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);

0 commit comments

Comments
 (0)