File tree 2 files changed +7
-3
lines changed
2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -234,10 +234,11 @@ def remove_done_callback(self, fn):
234
234
235
235
Returns the number of callbacks removed.
236
236
"""
237
+ count = len (self ._callbacks ) # since filtering may mutate the list
237
238
filtered_callbacks = [(f , ctx )
238
239
for (f , ctx ) in self ._callbacks
239
240
if f != fn ]
240
- removed_count = len ( self . _callbacks ) - len (filtered_callbacks )
241
+ removed_count = count - len (filtered_callbacks )
241
242
if removed_count :
242
243
self ._callbacks [:] = filtered_callbacks
243
244
return removed_count
Original file line number Diff line number Diff line change @@ -933,6 +933,7 @@ def test_use_after_free_fixed(self):
933
933
# Special thanks to Nico-Posada for the original PoC.
934
934
# See https://github.com/python/cpython/issues/125789.
935
935
936
+ asserter = self
936
937
fut = self ._new_future ()
937
938
938
939
class cb_pad :
@@ -941,11 +942,13 @@ def __eq__(self, other):
941
942
942
943
class evil (cb_pad ):
943
944
def __eq__ (self , other ):
944
- fut .remove_done_callback (None )
945
+ removed = fut .remove_done_callback (None )
946
+ asserter .assertEqual (removed , 1 )
945
947
return NotImplemented
946
948
947
949
fut .add_done_callback (cb_pad ())
948
- fut .remove_done_callback (evil ())
950
+ removed = fut .remove_done_callback (evil ())
951
+ self .assertEqual (removed , 1 )
949
952
950
953
951
954
@unittest .skipUnless (hasattr (futures , '_CFuture' ),
You can’t perform that action at this time.
0 commit comments