Skip to content

Commit

Permalink
test: netns: Guard against "double free" when failing to setup netns
Browse files Browse the repository at this point in the history
When used as a context manager, __exit__ will be called even though
__enter__ might throw an exception half way through. So there is no
guarantee that the instance is on the cleanup list when we get to
stop().
  • Loading branch information
wkz committed Nov 4, 2024
1 parent a2953d8 commit fbcf934
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/infamy/netns.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def start(self):
def stop(self):
self.sleeper.kill()
self.sleeper.wait()
self.Instances.remove(self)
if self in self.Instances:
self.Instances.remove(self)
time.sleep(0.5)

def __enter__(self):
Expand Down

0 comments on commit fbcf934

Please sign in to comment.