New submission from Oren Milman <ore...@gmail.com>: The following code results in refleaks: import sys import _elementtree builder = _elementtree.TreeBuilder() parser = _elementtree.XMLParser(target=builder)
refcount_before = sys.gettotalrefcount() parser.__init__(target=builder) print(sys.gettotalrefcount() - refcount_before) # should be close to 0 This is because _elementtree_XMLParser___init___impl() (in Modules/_elementtree.c) doesn't decref before assigning to fields of `self`. The following code also results in refleaks: import sys import _elementtree elem = _elementtree.Element(42) elem.__setstate__({'tag': 42, '_children': list(range(1000))}) refcount_before = sys.gettotalrefcount() elem.__setstate__({'tag': 42, '_children': []}) print(sys.gettotalrefcount() - refcount_before) # should be close to -1000 This is because element_setstate_from_attributes() doesn't decref the old children before storing the new children. I would open a PR to fix this soon. ---------- components: XML messages: 304145 nosy: Oren Milman priority: normal severity: normal status: open title: various refleaks in _elementtree type: resource usage versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue31758> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com