diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-06 09:07:11 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-06 09:07:11 (GMT) |
commit | d5f353ec8dc823dcaf24f927e0648b1891b9cebc (patch) | |
tree | d2c5a6dccf9e0ffbb9f28248e28455bfe1acbfbc /Objects | |
parent | 9c967611e3ef92f7aa605356c88027caa9dd9566 (diff) | |
download | cpython-d5f353ec8dc823dcaf24f927e0648b1891b9cebc.zip cpython-d5f353ec8dc823dcaf24f927e0648b1891b9cebc.tar.gz cpython-d5f353ec8dc823dcaf24f927e0648b1891b9cebc.tar.bz2 |
Issue #24726: Revert setting the value on the dict if
_odict_add_new_node() fails.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/odictobject.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 7a3ded0..98cbf94 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -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; }; |