From 6ad6f44920f95e85487d70bad58c31545abe83aa Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 12 Mar 2018 16:31:13 -0400 Subject: [PATCH] connection: Call virConnectClose and log the return value This can help us find object leaks within the code. virConnectClose is just a deference and will return 1 if other references are still floating around. --- virtManager/connection.py | 6 +++++- virtManager/engine.py | 2 +- virtinst/connection.py | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/virtManager/connection.py b/virtManager/connection.py index 68ad96832..c6f4b92c7 100644 --- a/virtManager/connection.py +++ b/virtManager/connection.py @@ -986,7 +986,6 @@ class vmmConnection(vmmGObject): self._storage_pool_cb_ids = [] self._node_device_cb_ids = [] - self._backend.close() self._stats = [] if self._init_object_event: @@ -995,6 +994,11 @@ class vmmConnection(vmmGObject): self._objects.cleanup() self._objects = _ObjectList() + closeret = self._backend.close() + if closeret == 1 and self.config.test_leak_debug: + logging.debug("LEAK: conn close() returned 1, " + "meaning refs may have leaked.") + self._change_state(self._STATE_DISCONNECTED) self._closing = False diff --git a/virtManager/engine.py b/virtManager/engine.py index 9a69382d0..acb93746b 100644 --- a/virtManager/engine.py +++ b/virtManager/engine.py @@ -478,7 +478,7 @@ class vmmEngine(vmmGObject): objs.remove(src.object_key) for name in objs: - logging.debug("Leaked %s", name) + logging.debug("LEAK: %s", name) logging.debug("Exiting app normally.") self._application.quit() diff --git a/virtinst/connection.py b/virtinst/connection.py index d7d0e8039..629d9f146 100644 --- a/virtinst/connection.py +++ b/virtinst/connection.py @@ -118,9 +118,13 @@ class VirtualConnection(object): return not bool(self._libvirtconn) def close(self): + ret = 0 + if self._libvirtconn: + ret = self._libvirtconn.close() self._libvirtconn = None self._uri = None self._fetch_cache = {} + return ret def fake_conn_predictable(self): return self._fake_conn_predictable