gh-94808: Fix refcounting in PyObject_Print tests (GH-117421)

This commit is contained in:
Petr Viktorin 2024-04-01 17:01:22 +02:00 committed by GitHub
parent dd44ab994b
commit 179869af92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 0 deletions

View File

@ -76,6 +76,8 @@ pyobject_print_noref_object(PyObject *self, PyObject *args)
if (PyObject_Print(test_string, fp, 0) < 0){
fclose(fp);
Py_SET_REFCNT(test_string, 1);
Py_DECREF(test_string);
return NULL;
}
@ -105,10 +107,12 @@ pyobject_print_os_error(PyObject *self, PyObject *args)
if (PyObject_Print(test_string, fp, 0) < 0) {
fclose(fp);
Py_DECREF(test_string);
return NULL;
}
fclose(fp);
Py_DECREF(test_string);
Py_RETURN_NONE;
}