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

This commit is contained in:
INADA Naoki 2017-08-24 14:55:17 +09:00 committed by GitHub
parent bf9075a0c5
commit a6296d34a4
14 changed files with 60 additions and 13 deletions

View file

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