diff options
author | Roger <wenrui@gmail.com> | 2010-12-09 07:02:10 +0800 |
---|---|---|
committer | Avery Pennarun <apenwarr@gmail.com> | 2010-12-09 19:20:07 -0800 |
commit | 82e1d1c1661a5c5b969dae9f32c72e0bda9e2334 (patch) | |
tree | 4506a461887f625fc30899cdab2e386f6dc4ad12 | |
parent | a497132c014002c4689526b98c5afe564326f9af (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.py | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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 |