]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] Fix possible memory leak in OrderedDict popitem (GH-145247) (#146537)
authorSergey Miryanov <sergey.miryanov@gmail.com>
Fri, 27 Mar 2026 21:40:50 +0000 (02:40 +0500)
committerGitHub <noreply@github.com>
Fri, 27 Mar 2026 21:40:50 +0000 (21:40 +0000)
Objects/odictobject.c

index bdd37fae99c5c036deba7b072922da2953f1c0b5..aee85eb72bcf06eac5077612513e594e6488a62d 100644 (file)
@@ -1168,8 +1168,10 @@ OrderedDict_popitem_impl(PyODictObject *self, int last)
     node = last ? _odict_LAST(self) : _odict_FIRST(self);
     key = Py_NewRef(_odictnode_KEY(node));
     value = _odict_popkey_hash((PyObject *)self, key, NULL, _odictnode_HASH(node));
-    if (value == NULL)
+    if (value == NULL) {
+        Py_DECREF(key);
         return NULL;
+    }
     item = PyTuple_Pack(2, key, value);
     Py_DECREF(key);
     Py_DECREF(value);