diff options
author | Ofey Chan <ofey206@gmail.com> | 2022-10-02 03:57:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-02 03:57:17 (GMT) |
commit | d63943860974f232b5f027dc6535d25d1b4d8fc0 (patch) | |
tree | 34ba0432e98431c890451f323cd79ecea5e2dc5b /Objects/exceptions.c | |
parent | 8baef8ae367041a5cfefb40b19c7b87e9bcb56a2 (diff) | |
download | cpython-d63943860974f232b5f027dc6535d25d1b4d8fc0.zip cpython-d63943860974f232b5f027dc6535d25d1b4d8fc0.tar.gz cpython-d63943860974f232b5f027dc6535d25d1b4d8fc0.tar.bz2 |
gh-97591: In `Exception.__setstate__()` acquire strong references before calling `tp_hash` slot (#97700)
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r-- | Objects/exceptions.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 3703fdc..80e98bb 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -167,8 +167,14 @@ BaseException_setstate(PyObject *self, PyObject *state) return NULL; } while (PyDict_Next(state, &i, &d_key, &d_value)) { - if (PyObject_SetAttr(self, d_key, d_value) < 0) + Py_INCREF(d_key); + Py_INCREF(d_value); + int res = PyObject_SetAttr(self, d_key, d_value); + Py_DECREF(d_value); + Py_DECREF(d_key); + if (res < 0) { return NULL; + } } } Py_RETURN_NONE; |