Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit d5f353e

Browse files
Issue python#24726: Revert setting the value on the dict if
_odict_add_new_node() fails.
1 parent 9c96761 commit d5f353e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Objects/odictobject.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,13 @@ PyODict_SetItem(PyObject *od, PyObject *key, PyObject *value) {
17211721
int res = PyDict_SetItem(od, key, value);
17221722
if (res == 0) {
17231723
res = _odict_add_new_node((PyODictObject *)od, key);
1724-
/* XXX Revert setting the value on the dict? */
1724+
if (res < 0) {
1725+
/* Revert setting the value on the dict */
1726+
PyObject *exc, *val, *tb;
1727+
PyErr_Fetch(&exc, &val, &tb);
1728+
(void) PyDict_DelItem(od, key);
1729+
_PyErr_ChainExceptions(exc, val, tb);
1730+
}
17251731
}
17261732
return res;
17271733
};

0 commit comments

Comments
 (0)