« M2Crypto 0.13 | Main | M2Crypto 0.13.1 »

31 March 2004

SSL.Connection.setblocking

Fix to memory leak

There is a memory leak in M2Crypto.SSL.Connection.setblocking.

Andre Reitz describes it thusly:

There is a memoryleak if you use
the function setblocking..... of SSL.Connection
 
e.g.:
  self._write_bio
  self._read_bio
..are bound instance methods, which referr to the Connection object

it seems that because of this backreference,
the cyclic garbagecollection would be needed to free
the Connection object,
but because of the __del__ method in Connection, it can
never be freed.

Michael Dunstan offers this patch:

     def setblocking(self, mode):
         """Set this connection's underlying socket to _mode_."""
         self.socket.setblocking(mode)
         if mode:
-            self.send = self.write = self._write_bio
+            self.send = self.write = Connection._write_bio
_            self.recv = self.read = self._read_bio
+            self.recv = self.read = Connection._read_bio
         else:
-            self.send = self.write = self._write_nbio
+            self.send = self.write = Connection._write_nbio
-            self.recv = self.read = self._read_nbio
+            self.recv = self.read = Connection._read_nbio

Michael explains, in the context of his running ZServerSSL:

This does have different meaning but I don't think that affects the
functionality of the class in this case.
 
Since applying the patch we have not had any memory problems for some
time. About 8 months now.

Thanks Andre and Michael.

I'd thought of rolling out 0.13p1 for this, but I've since received more patches (new functionality, not fixes ;-), so I'll hold off 0.13p1 for a bit.

Please apply the above fix to your copy.


Posted by ngps at 00:17 | Comments (0) | Trackbacks (0)
Comments
There is no comment.
Trackbacks
Please send trackback to:http://sandbox.rulemaker.net/ngps/17/tbping
There is no trackback.