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 | |
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')
-rw-r--r-- | Modules/_collectionsmodule.c | 4 | ||||
-rw-r--r-- | Modules/_elementtree.c | 4 | ||||
-rw-r--r-- | Modules/_functoolsmodule.c | 7 | ||||
-rw-r--r-- | Modules/_io/bytesio.c | 2 | ||||
-rw-r--r-- | Modules/_json.c | 6 | ||||
-rw-r--r-- | Modules/_ssl.c | 3 | ||||
-rw-r--r-- | Modules/_struct.c | 2 |
7 files changed, 24 insertions, 4 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index aa582ed..adbe789 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1717,6 +1717,8 @@ dequeiter_traverse(dequeiterobject *dio, visitproc visit, void *arg) static void dequeiter_dealloc(dequeiterobject *dio) { + /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyObject_GC_UnTrack(dio); Py_XDECREF(dio->deque); PyObject_GC_Del(dio); } @@ -2097,6 +2099,8 @@ static PyMemberDef defdict_members[] = { static void defdict_dealloc(defdictobject *dd) { + /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyObject_GC_UnTrack(dd); Py_CLEAR(dd->default_factory); PyDict_Type.tp_dealloc((PyObject *)dd); } diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 3537f19..857005a 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -627,6 +627,7 @@ element_gc_clear(ElementObject *self) static void element_dealloc(ElementObject* self) { + /* bpo-31095: UnTrack is needed before calling any callbacks */ PyObject_GC_UnTrack(self); Py_TRASHCAN_SAFE_BEGIN(self) @@ -2076,6 +2077,8 @@ elementiter_dealloc(ElementIterObject *it) { Py_ssize_t i = it->parent_stack_used; it->parent_stack_used = 0; + /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyObject_GC_UnTrack(it); while (i--) Py_XDECREF(it->parent_stack[i].parent); PyMem_Free(it->parent_stack); @@ -2083,7 +2086,6 @@ elementiter_dealloc(ElementIterObject *it) Py_XDECREF(it->sought_tag); Py_XDECREF(it->root_element); - PyObject_GC_UnTrack(it); PyObject_GC_Del(it); } 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); diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index 42c7f79..ba33f8c 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -1084,6 +1084,8 @@ bytesiobuf_traverse(bytesiobuf *self, visitproc visit, void *arg) static void bytesiobuf_dealloc(bytesiobuf *self) { + /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyObject_GC_UnTrack(self); Py_CLEAR(self->source); Py_TYPE(self)->tp_free(self); } diff --git a/Modules/_json.c b/Modules/_json.c index 6cc31c6..54fc90c 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -655,7 +655,8 @@ py_encode_basestring(PyObject* self UNUSED, PyObject *pystr) static void scanner_dealloc(PyObject *self) { - /* Deallocate scanner object */ + /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyObject_GC_UnTrack(self); scanner_clear(self); Py_TYPE(self)->tp_free(self); } @@ -1778,7 +1779,8 @@ bail: static void encoder_dealloc(PyObject *self) { - /* Deallocate Encoder */ + /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyObject_GC_UnTrack(self); encoder_clear(self); Py_TYPE(self)->tp_free(self); } diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 1380c57..e8abcb2 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -2778,6 +2778,8 @@ context_clear(PySSLContext *self) static void context_dealloc(PySSLContext *self) { + /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyObject_GC_UnTrack(self); context_clear(self); SSL_CTX_free(self->ctx); #ifdef OPENSSL_NPN_NEGOTIATED @@ -4292,6 +4294,7 @@ static PyTypeObject PySSLMemoryBIO_Type = { static void PySSLSession_dealloc(PySSLSession *self) { + /* bpo-31095: UnTrack is needed before calling any callbacks */ PyObject_GC_UnTrack(self); Py_XDECREF(self->ctx); if (self->session != NULL) { diff --git a/Modules/_struct.c b/Modules/_struct.c index b5fbc43..69a1e99 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1589,6 +1589,8 @@ typedef struct { static void unpackiter_dealloc(unpackiterobject *self) { + /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyObject_GC_UnTrack(self); Py_XDECREF(self->so); PyBuffer_Release(&self->buf); PyObject_GC_Del(self); |