From d38883833a9142eda4d6ccfb91df3026078736e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 6 Nov 2015 23:54:04 +0100 Subject: [PATCH] core: ensure that QubesDB connections are closed when disposing a VM collection There are some circular dependencies (TemplateVM.appvms, NetVM.connected_vms, and probably more), which prevents garbage collector from cleaning them. Fixes QubesOS/qubes-issues#1380 --- core/qubes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/qubes.py b/core/qubes.py index a66f3188..c32a46fe 100755 --- a/core/qubes.py +++ b/core/qubes.py @@ -307,6 +307,16 @@ class QubesVmCollection(dict): def clear(self): self.log.debug('clear()') + # Hack for releasing FDs, which otherwise would be leaked because of + # circular dependencies on QubesVMs objects (so garbage collector + # doesn't handle them). See #1380 for details + for vm in self.values(): + try: + if vm._qdb_connection: + vm._qdb_connection.close() + vm._qdb_connection = None + except AttributeError: + pass super(QubesVmCollection, self).clear() def values(self):