diff options
author | Victor Stinner <vstinner@python.org> | 2019-10-07 22:09:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-07 22:09:31 (GMT) |
commit | 1b1845569539db5c1a6948a5d32daea381f1e35f (patch) | |
tree | 9e9b867120a68e7f1f2c1f270dd102a6297adca6 /Modules/pyexpat.c | |
parent | 7775349895088a7ae68cecf0c74cf817f15e2c74 (diff) | |
download | cpython-1b1845569539db5c1a6948a5d32daea381f1e35f.zip cpython-1b1845569539db5c1a6948a5d32daea381f1e35f.tar.gz cpython-1b1845569539db5c1a6948a5d32daea381f1e35f.tar.bz2 |
bpo-38392: PyObject_GC_Track() validates object in debug mode (GH-16615)
In debug mode, PyObject_GC_Track() now calls tp_traverse() of the
object type to ensure that the object is valid: test that objects
visited by tp_traverse() are valid.
Fix pyexpat.c: only track the parser in the GC once the parser is
fully initialized.
Diffstat (limited to 'Modules/pyexpat.c')
-rw-r--r-- | Modules/pyexpat.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index d912335..9016734 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -938,7 +938,6 @@ pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self, new_parser->handlers = 0; new_parser->intern = self->intern; Py_XINCREF(new_parser->intern); - PyObject_GC_Track(new_parser); if (self->buffer != NULL) { new_parser->buffer = PyMem_Malloc(new_parser->buffer_size); @@ -975,6 +974,8 @@ pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self, handler_info[i].handler); } } + + PyObject_GC_Track(new_parser); return (PyObject *)new_parser; } @@ -1122,7 +1123,6 @@ newxmlparseobject(const char *encoding, const char *namespace_separator, PyObjec self->handlers = NULL; self->intern = intern; Py_XINCREF(self->intern); - PyObject_GC_Track(self); /* namespace_separator is either NULL or contains one char + \0 */ self->itself = XML_ParserCreate_MM(encoding, &ExpatMemoryHandler, @@ -1152,6 +1152,7 @@ newxmlparseobject(const char *encoding, const char *namespace_separator, PyObjec } clear_handlers(self, 1); + PyObject_GC_Track(self); return (PyObject*)self; } |