Author Oren Milman
Recipients Oren Milman
Date 2017-10-11.14:53:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1507733619.97.0.213398074469.issue31758@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-10-11 14:53:40Oren Milmansetrecipients: + Oren Milman
2017-10-11 14:53:39Oren Milmansetmessageid: <1507733619.97.0.213398074469.issue31758@psf.upfronthosting.co.za>
2017-10-11 14:53:39Oren Milmanlinkissue31758 messages
2017-10-11 14:53:39Oren Milmancreate