https://github.com/python/cpython/commit/ed38c20dd34a40ee7c27c3655c17298404044b78
commit: ed38c20dd34a40ee7c27c3655c17298404044b78
branch: 3.14
author: Sergey Miryanov <[email protected]>
committer: vstinner <[email protected]>
date: 2026-03-27T21:40:50Z
summary:

[3.14] Fix possible memory leak in OrderedDict popitem (GH-145247) (#146537)

files:
M Objects/odictobject.c

diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index bdd37fae99c5c0..aee85eb72bcf06 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -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);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to