diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-10-02 04:18:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-02 04:18:38 (GMT) |
commit | c6fcbb4928ced97df81d2cef6c5dcec6bc7dcab7 (patch) | |
tree | 7d222d7c3d8d1a339754a290a4e2ee631dda526c /Objects | |
parent | a4fbb949659b86b0925b20a9ef6bc2877f397252 (diff) | |
download | cpython-c6fcbb4928ced97df81d2cef6c5dcec6bc7dcab7.zip cpython-c6fcbb4928ced97df81d2cef6c5dcec6bc7dcab7.tar.gz cpython-c6fcbb4928ced97df81d2cef6c5dcec6bc7dcab7.tar.bz2 |
gh-97591: In `Exception.__setstate__()` acquire strong references before calling `tp_hash` slot (GH-97700)
(cherry picked from commit d63943860974f232b5f027dc6535d25d1b4d8fc0)
Co-authored-by: Ofey Chan <ofey206@gmail.com>
Diffstat (limited to 'Objects')
-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 9639b44..5dfd1d6 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -156,8 +156,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; |