]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111789: Use PyDict_GetItemRef() in Python/_warnings.c (gh-112080)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 27 Nov 2023 17:58:43 +0000 (19:58 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Nov 2023 17:58:43 +0000 (18:58 +0100)
Python/_warnings.c

index 4b7fb888247145fb26f7c534d22d3b6a90c60768..d4765032824e5666ddf11203d2c802ca2879f9da 100644 (file)
@@ -425,15 +425,15 @@ already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key,
         Py_DECREF(version_obj);
     }
     else {
-        already_warned = PyDict_GetItemWithError(registry, key);
+        if (PyDict_GetItemRef(registry, key, &already_warned) < 0) {
+            return -1;
+        }
         if (already_warned != NULL) {
             int rc = PyObject_IsTrue(already_warned);
+            Py_DECREF(already_warned);
             if (rc != 0)
                 return rc;
         }
-        else if (PyErr_Occurred()) {
-            return -1;
-        }
     }
 
     /* This warning wasn't found in the registry, set it. */