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

index 0cb352b4e09e7366761306b230143964f5342325..ca5f7c8d3a8c09c4edce05a20d2f71c5d131f75c 100644 (file)
@@ -1148,8 +1148,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);