Skip to content

Commit 3828280

Browse files
committed
[Python] Clear TList in tseqcollection_itemaccess.py:test_delitem
Clear the TList at the end of the `test_delitem` unit test in tseqcollection_itemaccess.py to make sure the contained list elements are still alive when the list is cleared. Otherwise, the elements might be deleted before the containing list, depending on the order or garbage collection.
1 parent 5d902d8 commit 3828280

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

bindings/pyroot/pythonizations/test/tseqcollection_itemaccess.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ def test_setitem(self):
125125
with self.assertRaises(TypeError):
126126
sc[1.0] = ROOT.TObject()
127127

128+
# Clear before the added element might be garbage collected,
129+
# to avoid dangling pointer access.
130+
sc.Clear()
131+
128132
def test_setitem_slice(self):
129133
sc1 = self.create_tseqcollection()
130134
sc2 = self.create_tseqcollection()
@@ -239,6 +243,8 @@ def test_delitem(self):
239243
with self.assertRaises(TypeError):
240244
del sc[1.0]
241245

246+
sc.Clear()
247+
242248
def test_delitem_slice(self):
243249
# Delete all items
244250
sc1 = self.create_tseqcollection()

0 commit comments

Comments
 (0)