changeset: 98983:1594c23d8c2f branch: 3.5 parent: 98981:ad44d551c13c user: Serhiy Storchaka date: Fri Nov 06 11:07:11 2015 +0200 files: Objects/odictobject.c description: Issue #24726: Revert setting the value on the dict if _odict_add_new_node() fails. diff -r ad44d551c13c -r 1594c23d8c2f Objects/odictobject.c --- a/Objects/odictobject.c Fri Nov 06 10:39:51 2015 +0200 +++ b/Objects/odictobject.c Fri Nov 06 11:07:11 2015 +0200 @@ -1721,7 +1721,13 @@ 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; };