]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94808: Fix refcounting in PyObject_Print tests (GH-117421)
authorPetr Viktorin <encukou@gmail.com>
Mon, 1 Apr 2024 15:01:22 +0000 (17:01 +0200)
committerGitHub <noreply@github.com>
Mon, 1 Apr 2024 15:01:22 +0000 (17:01 +0200)
Modules/_testcapi/object.c

index ce5b574ec5ce8f749d498fda9d4bbdc4f02da434..8dd34cf4fc47d43c652975811ed2f3c7558bf5a2 100644 (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;
 }