From 69e5de40227ee046e9f19414fb90b924e4f739f8 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 3 Jun 2018 20:52:12 +0200 Subject: Fix crash during GC when _ParserContext and _ParserSchemaValidationContext instances participate in a reference cycle and the _ParserContext gets cleared by the GC before it can disconnect the _ParserSchemaValidationContext. Closes #266. --- CHANGES.txt | 11 +++++++++++ src/lxml/parser.pxi | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1a017ee0..ee049c72 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,17 @@ lxml changelog ============== +4.2.2 (2018-??-??) +================== + +Bugs fixed +---------- + +* GH#266: Fix sporadic crash during GC when parse-time schema validation is used + and the parser participates in a reference cycle. + Original patch by Julien Greard. + + 4.2.1 (2018-03-21) ================== diff --git a/src/lxml/parser.pxi b/src/lxml/parser.pxi index 869bf0e7..bcf4da6f 100644 --- a/src/lxml/parser.pxi +++ b/src/lxml/parser.pxi @@ -508,6 +508,7 @@ xmlparser.xmlSetExternalEntityLoader(_local_r ## Parsers ############################################################ +@cython.no_gc_clear # May have to call "self._validator.disconnect()" on dealloc. @cython.internal cdef class _ParserContext(_ResolverContext): cdef _ErrorLog _error_log @@ -531,7 +532,7 @@ cdef class _ParserContext(_ResolverContext): python.PyThread_free_lock(self._lock) self._lock = NULL if self._c_ctxt is not NULL: - if self._validator is not None: + if self._validator is not NULL and self._validator is not None: # If the parser was not closed correctly (e.g. interrupted iterparse()), # and the schema validator wasn't freed and cleaned up yet, the libxml2 SAX # validator plug might still be in place, which will make xmlFreeParserCtxt() -- cgit v1.2.1