Good afternoon, 

I observe a very strange behavior: the following code segfaults. Looks like resource limit kicks in (because huge_tree=True solves the problem).
But there is a strange thing: commenting out etree.fromstring() solves the problem. Is this a bug?

BTW, creating a new parser in the loop does not help. May be parser should be closed/deinitialized somehow?

Here is the code (mirror: http://dpaste.com/13G071K):

#!/usr/bin/env python

from lxml import etree
import string
import random

def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

parser= etree.XMLParser(
    # huge_tree=True
)

# Bug? Without it all works fine
etree.fromstring('<x></x>', parser=parser)

tag = etree.QName('tag')
value = etree.QName('id')
for i in range(1, 1_000_000):
    # this doesn't help at all, parsers share resource counters?
    parser = etree.XMLParser()
    x = parser.makeelement(tag)
    rand_id = id_generator()
    x.set(f"x_{rand_id*100}", value)
    for c in x.iter():
        c.attrib.items()

--
Kind Regards,
Alexandre