Skip to content

Commit 179869a

Browse files
authored
gh-94808: Fix refcounting in PyObject_Print tests (GH-117421)
1 parent dd44ab9 commit 179869a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Modules/_testcapi/object.c

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ pyobject_print_noref_object(PyObject *self, PyObject *args)
7676

7777
if (PyObject_Print(test_string, fp, 0) < 0){
7878
fclose(fp);
79+
Py_SET_REFCNT(test_string, 1);
80+
Py_DECREF(test_string);
7981
return NULL;
8082
}
8183

@@ -105,10 +107,12 @@ pyobject_print_os_error(PyObject *self, PyObject *args)
105107

106108
if (PyObject_Print(test_string, fp, 0) < 0) {
107109
fclose(fp);
110+
Py_DECREF(test_string);
108111
return NULL;
109112
}
110113

111114
fclose(fp);
115+
Py_DECREF(test_string);
112116

113117
Py_RETURN_NONE;
114118
}

0 commit comments

Comments
 (0)