[PYTHON-CRYPTO] Memoryleak in SSL.Connection

Andre Reitz reitz at INWORKS.DE
Thu Apr 1 21:49:07 CEST 2004


Bad news.......

This patch doesnt work with python 2.2.3 !!!!

something like this happens
  TypeError: unbound method ...() must be called with ... instance as first argument (got nothing instead)


but....
here is my patch, which should work in any case:

(but not so efficient)


Greetings, Andre'


--- M2Crypto/SSL/Connection.py  2004-03-25 07:36:04.000000000 +0100
+++ /home/andre/m2crypto-0.13/M2Crypto/SSL/Connection.py        2004-04-01 21:32:45.000000000 +0200
@@ -120,34 +120,26 @@
         connection."""
         return m2.ssl_pending(self.ssl)

-    def _write_bio(self, data):
-        return m2.ssl_write(self.ssl, data)
-
-    def _write_nbio(self, data):
-        return m2.ssl_write_nbio(self.ssl, data)
-
-    def _read_bio(self, size=1024):
-        if size <= 0:
-            raise ValueError, 'size <= 0'
-        return m2.ssl_read(self.ssl, size)
-
-    def _read_nbio(self, size=1024):
+    def _read(self,size=1024):
         if size <= 0:
             raise ValueError, 'size <= 0'
+        if self._blocking:
+            return m2.ssl_read(self.ssl, size)
         return m2.ssl_read_nbio(self.ssl, size)

-    sendall = send = write = _write_bio
-    recv = read  = _read_bio
+    def _write(self,data):
+        if self._blocking:
+            m2.ssl_write(self.ssl, data)
+        return m2.ssl_write_nbio(self.ssl, data)
+
+    sendall = send = write = _write
+    recv = read  = _read

+    _blocking=1
     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.recv = self.read = self._read_bio
-        else:
-            self.send = self.write = self._write_nbio
-            self.recv = self.read = self._read_nbio
+        self._blocking=mode

     def fileno(self):
         return self.socket.fileno()












On Tue, 30 Mar 2004 23:55:21 +0800
Ng Pheng Siong <ngps at POST1.COM> wrote:

> On Tue, Mar 30, 2004 at 07:25:36PM +1200, Michael Dunstan wrote:
> > I have seen the same leak when running ZServerSSL. Had to restart the
> > server every few days. Until the following change was made for
> > setblocking:
> >
> > -            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
> >
> > Since applying the patch we have not had any memory problems for some
> > time. About 8 months now.
>
> Great! Thanks for the patch Michael.
>
> Now to roll out 0.13p1!
>
> > It is quite a simple matter to correct the headers used for the image
> > 304's in Zope. There is even an issue in the zope collector about this:
> > http://collector.zope.org/Zope/544. Looks like this incorrect handling
> > of the headers in zope is intentional to support caching in some
> > relic version of apache configured as a proxy server.
>
> Bad Zope. No biscuit for Zope.
>
>
> Cheers.
>
> --
> Ng Pheng Siong <ngps at netmemetic.com>
>
> http://firewall.rulemaker.net -+- Firewall Change Management & Version Control
> http://sandbox.rulemaker.net/ngps -+- Open Source Python Crypto & SSL
-------------- next part --------------
A non-text attachment was scrubbed...
Name: m2crypto-0.13-andre-nbio.patch
Type: application/octet-stream
Size: 1608 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-crypto/attachments/20040401/dc7aeb51/attachment.obj>


More information about the python-crypto mailing list