summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger <wenrui@gmail.com>2010-12-09 07:02:10 +0800
committerAvery Pennarun <apenwarr@gmail.com>2010-12-09 19:20:07 -0800
commit82e1d1c1661a5c5b969dae9f32c72e0bda9e2334 (patch)
tree4506a461887f625fc30899cdab2e386f6dc4ad12
parenta497132c014002c4689526b98c5afe564326f9af (diff)
Fix memory leak of MuxWrapper object.
(Note by apenwarr: I used Roger's original patch as the basis for this one, but implemented it a different way. All errors are thus my fault, but Roger gets the credit for actually tracking down the circular reference that caused the memory leak.)
-rw-r--r--ssnet.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/ssnet.py b/ssnet.py
index 05ff447..e8dde65 100644
--- a/ssnet.py
+++ b/ssnet.py
@@ -264,6 +264,8 @@ class Proxy(Handler):
if (self.wrap1.shut_read and self.wrap2.shut_read and
not self.wrap1.buf and not self.wrap2.buf):
self.ok = False
+ self.wrap1.nowrite()
+ self.wrap2.nowrite()
class Mux(Handler):
@@ -425,11 +427,19 @@ class MuxWrapper(SockWrapper):
def noread(self):
if not self.shut_read:
self.shut_read = True
+ self.maybe_close()
def nowrite(self):
if not self.shut_write:
self.shut_write = True
self.mux.send(self.channel, CMD_EOF, '')
+ self.maybe_close()
+
+ def maybe_close(self):
+ if self.shut_read and self.shut_write:
+ # remove the mux's reference to us. The python garbage collector
+ # will then be able to reap our object.
+ self.mux.channels[self.channel] = None
def too_full(self):
return self.mux.too_full