From be62d3b7e305dbad13e886e8b797b52bb33765b7 Mon Sep 17 00:00:00 2001 From: Kenneth Giusti Date: Wed, 16 Sep 2015 15:07:01 -0400 Subject: [PATCH] Bugfix: fix leak of underlying proton objects (cherry picked from commit 67f78f9e7e86f2189ce8e5d22dd3ccb5c56b8dcd) --- pyngus/connection.py | 19 ++++++++++++++++--- pyngus/link.py | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pyngus/connection.py b/pyngus/connection.py index 53807fd..7aeb47e 100644 --- a/pyngus/connection.py +++ b/pyngus/connection.py @@ -113,7 +113,7 @@ class Connection(Endpoint): not reentrant """ def wrap(self, *args, **kws): - if self._callback_lock.in_callback: + if self._callback_lock and self._callback_lock.in_callback: m = "Connection %s cannot be invoked from a callback!" % func raise RuntimeError(m) return func(self, *args, **kws) @@ -396,20 +396,33 @@ class Connection(Endpoint): LOG.debug("Connection with buffered output destroyed") self._error = "Destroyed by the application" self._handler = None - self._sender_links.clear() - self._receiver_links.clear() + self._properties = None + tmp = self._sender_links.copy() + for l in tmp.values(): + l.destroy() + assert(len(self._sender_links) == 0) + tmp = self._receiver_links.copy() + for l in tmp.values(): + l.destroy() + assert(len(self._receiver_links) == 0) + self._timers = None + self._timers_heap = None self._container.remove_connection(self._name) self._container = None self._user_context = None + self._callback_lock = None if self._transport_bound: self._pn_transport.unbind() self._pn_transport = None + self._pn_connection.free() self._pn_connection = None if _PROTON_VERSION < (0, 8): # memory leak: drain the collector before releasing it while self._pn_collector.peek(): self._pn_collector.pop() self._pn_collector = None + self._pn_sasl = None + self._pn_ssl = None _REMOTE_REQ = (proton.Endpoint.LOCAL_UNINIT | proton.Endpoint.REMOTE_ACTIVE) diff --git a/pyngus/link.py b/pyngus/link.py index 5951fc5..b1e3cbb 100644 --- a/pyngus/link.py +++ b/pyngus/link.py @@ -210,6 +210,7 @@ class _Link(Endpoint): self._user_context = None self._connection = None self._handler = None + self._callback_lock = None if self._pn_link: session = self._pn_link.session.context self._pn_link.context = None