]> granicus.if.org Git - python/commitdiff
Issue #24726: Revert setting the value on the dict if
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 6 Nov 2015 09:07:11 +0000 (11:07 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 6 Nov 2015 09:07:11 +0000 (11:07 +0200)
_odict_add_new_node() fails.

Objects/odictobject.c

index 7a3ded09e6b8bba84ceea05af063521468b6274e..98cbf9496dca47eef350cca4d7962d2eddd97a56 100644 (file)
@@ -1721,7 +1721,13 @@ PyODict_SetItem(PyObject *od, PyObject *key, PyObject *value) {
     int res = PyDict_SetItem(od, key, value);
     if (res == 0) {
         res = _odict_add_new_node((PyODictObject *)od, key);
-        /* XXX Revert setting the value on the dict? */
+        if (res < 0) {
+            /* Revert setting the value on the dict */
+            PyObject *exc, *val, *tb;
+            PyErr_Fetch(&exc, &val, &tb);
+            (void) PyDict_DelItem(od, key);
+            _PyErr_ChainExceptions(exc, val, tb);
+        }
     }
     return res;
 };