diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2018-06-03 20:52:12 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2018-06-03 20:52:12 +0200 |
commit | 69e5de40227ee046e9f19414fb90b924e4f739f8 (patch) | |
tree | 29c68bc621775c1c7bd3644006bc27ce15317a7b | |
parent | 2d07213a889d80ea54360dc7b0d204ae45266b89 (diff) | |
download | python-lxml-69e5de40227ee046e9f19414fb90b924e4f739f8.tar.gz |
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.
-rw-r--r-- | CHANGES.txt | 11 | ||||
-rw-r--r-- | src/lxml/parser.pxi | 3 |
2 files changed, 13 insertions, 1 deletions
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(<xmlparser.xmlExternalEntityLoader>_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 <void*>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() |