bpo-31095: fix potential crash during GC (GH-3195)

(cherry picked from commit a6296d34a4)
This commit is contained in:
INADA Naoki 2017-09-04 12:31:09 +09:00 committed by GitHub
parent 7d8282d25d
commit 2eea952b1b
14 changed files with 60 additions and 13 deletions

View file

@ -556,6 +556,7 @@ set_dealloc(PySetObject *so)
setentry *entry;
Py_ssize_t used = so->used;
/* bpo-31095: UnTrack is needed before calling any callbacks */
PyObject_GC_UnTrack(so);
Py_TRASHCAN_SAFE_BEGIN(so)
if (so->weakreflist != NULL)
@ -812,6 +813,8 @@ typedef struct {
static void
setiter_dealloc(setiterobject *si)
{
/* bpo-31095: UnTrack is needed before calling any callbacks */
_PyObject_GC_UNTRACK(si);
Py_XDECREF(si->si_set);
PyObject_GC_Del(si);
}