gh-97591: In Exception.__setstate__() acquire strong references before calling tp_hash slot (GH-97700)

(cherry picked from commit d639438609)

Co-authored-by: Ofey Chan <ofey206@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-10-01 21:19:57 -07:00 committed by GitHub
parent 9189cd6b05
commit dbde686a49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View file

@ -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;