diff options
author | INADA Naoki <methane@users.noreply.github.com> | 2017-08-24 05:55:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-24 05:55:17 (GMT) |
commit | a6296d34a478b4f697ea9db798146195075d496c (patch) | |
tree | 6a26d56297f7d85dd6a8f18bca96e0c4ffb60802 /Modules/_functoolsmodule.c | |
parent | bf9075a0c55186d2f34df63e6c8512dd6414ff4b (diff) | |
download | cpython-a6296d34a478b4f697ea9db798146195075d496c.zip cpython-a6296d34a478b4f697ea9db798146195075d496c.tar.gz cpython-a6296d34a478b4f697ea9db798146195075d496c.tar.bz2 |
bpo-31095: fix potential crash during GC (GH-2974)
Diffstat (limited to 'Modules/_functoolsmodule.c')
-rw-r--r-- | Modules/_functoolsmodule.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index da1d2e1..33761a4 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -113,6 +113,7 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw) static void partial_dealloc(partialobject *pto) { + /* bpo-31095: UnTrack is needed before calling any callbacks */ PyObject_GC_UnTrack(pto); if (pto->weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *) pto); @@ -1073,7 +1074,11 @@ lru_cache_clear_list(lru_list_elem *link) static void lru_cache_dealloc(lru_cache_object *obj) { - lru_list_elem *list = lru_cache_unlink_list(obj); + lru_list_elem *list; + /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyObject_GC_UnTrack(obj); + + list = lru_cache_unlink_list(obj); Py_XDECREF(obj->maxsize_O); Py_XDECREF(obj->func); Py_XDECREF(obj->cache); |