From a4a4a49eaeb007b159e5bdfb8c9fcb664db52e03 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Mon, 4 Nov 2024 10:31:57 +0100 Subject: [PATCH] test: netns: Guard against "double free" when failing to setup netns 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(). --- test/infamy/netns.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/infamy/netns.py b/test/infamy/netns.py index dfffe114..e7de7d87 100644 --- a/test/infamy/netns.py +++ b/test/infamy/netns.py @@ -87,7 +87,8 @@ class IsolatedMacVlans: 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):