Memory error with incomplete iterparse iteration
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Fix Released
|
High
|
scoder |
Bug Description
When looping over the output of iterparse with a supplied schema, I get a memory error when python exits if the iteration was exited early.
The error is:
python3(
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
This error does not occur if a schema is not supplied to iterparse. It also does not occur when the breaking out of the loop happens. It happens when python eventually exits.
System information and minimal working example code + input files follow:
OS info:
$ uname -a
Darwin nix 17.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-
Requested information:
>>> print("%-20s: %s" % ('Python', sys.version_info))
Python : sys.version_
>>> print("%-20s: %s" % ('lxml.etree', etree.LXML_
lxml.etree : (4, 1, 1, 0)
>>> print("%-20s: %s" % ('libxml used', etree.LIBXML_
libxml used : (2, 9, 5)
>>> print("%-20s: %s" % ('libxml compiled', etree.LIBXML_
libxml compiled : (2, 9, 5)
>>> print("%-20s: %s" % ('libxslt used', etree.LIBXSLT_
libxslt used : (1, 1, 32)
>>> print("%-20s: %s" % ('libxslt compiled', etree.LIBXSLT_
libxslt compiled : (1, 1, 29)
Files / code to reproduce:
test.py
-----
#!/usr/bin/env python3
from lxml.etree import parse, XMLSchema, iterparse
xml_file = 'test.xml'
xsd_file = 'library.xsd'
xsd_document = parse(xsd_file)
schema = XMLSchema(
context = iterparse(xml_file, schema=schema, events=['end'])
for _, elem in context:
exit()
library.xsd
-----
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:d="http://
xmlns:xs="http://
targetNamesp
<xs:element name="metadata" type="xs:string"/>
</xs:schema>
test.xml
--------
<?xml version="1.0"?>
<d:document xmlns:d="http://
<d:metadata>
</d:document>
Changed in lxml: | |
milestone: | none → 4.2.0 |
Changed in lxml: | |
status: | Fix Committed → Fix Released |
Thanks for the report. I can reproduce this. Might still be a problem in libxml2, but I'll investigate.