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
This commit is contained in:
Marek Marczykowski-Górecki 2015-11-06 23:54:04 +01:00
parent a7b124d6da
commit d38883833a
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -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):