]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
tests: minimize file descriptor leaks
authorVincent Bernat <vincent@bernat.im>
Mon, 26 Dec 2016 08:56:06 +0000 (09:56 +0100)
committerVincent Bernat <vincent@bernat.im>
Mon, 26 Dec 2016 08:56:06 +0000 (09:56 +0100)
This is not perfect as we still rely on garbage collection to do its job
and it seems it is not running often enough.

tests/integration/fixtures/namespaces.py

index 6257df220dd52054854840e19b1d528fa7de9f4f..e278bce1c46af689e1a45922a2df83a7c03f7877 100644 (file)
@@ -81,8 +81,17 @@ class Namespace(object):
         os.close(self.pipe[0])
         if 'pid' not in namespaces:
             os.close(self.pipe[1])
+            self.pipe = None
             os.waitpid(pid, 0)
 
+    def __del__(self):
+        for fd in self.next:
+            os.close(fd)
+        for fd in self.previous:
+            os.close(fd)
+        if self.pipe is not None:
+            os.close(self.pipe[1])
+
     def child(self):
         """Cloned child.