bpo-31499, xml.etree: Fix xmlparser_gc_clear() crash (#3641)

* bpo-31499, xml.etree: Fix xmlparser_gc_clear() crash

xml.etree: xmlparser_gc_clear() now sets self.parser to NULL to prevent a
crash in xmlparser_dealloc() if xmlparser_gc_clear() was called previously
by the garbage collector, because the parser was part of a reference cycle.

Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Victor Stinner 2017-09-18 05:29:37 -07:00 committed by GitHub
parent 9b47af6537
commit e727d41ffc
3 changed files with 26 additions and 1 deletions

View file

@ -3411,7 +3411,11 @@ xmlparser_gc_traverse(XMLParserObject *self, visitproc visit, void *arg)
static int
xmlparser_gc_clear(XMLParserObject *self)
{
EXPAT(ParserFree)(self->parser);
if (self->parser != NULL) {
XML_Parser parser = self->parser;
self->parser = NULL;
EXPAT(ParserFree)(parser);
}
Py_CLEAR(self->handle_close);
Py_CLEAR(self->handle_pi);