[Python-checkins] cpython: Issue #15977: Fix memory leak in Modules/_ssl.c when the function

georg.brandl python-checkins at python.org
Mon Sep 24 07:46:59 CEST 2012


http://hg.python.org/cpython/rev/4cf53684e14e
changeset:   79114:4cf53684e14e
user:        Christian Heimes <christian at cheimes.de>
date:        Thu Sep 20 12:42:54 2012 +0200
summary:
  Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times

files:
  Misc/NEWS      |  3 +++
  Modules/_ssl.c |  7 +++++++
  2 files changed, 10 insertions(+), 0 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -201,6 +201,9 @@
 - Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by
   Daniel Ellis.
 
+- Issue #15977: Fix memory leak in Modules/_ssl.c when the function
+  _set_npn_protocols() is called multiple times, thanks to Daniel Sommermann.
+
 Tests
 -----
 
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1713,6 +1713,9 @@
         return NULL;
     }
     self->ctx = ctx;
+#ifdef OPENSSL_NPN_NEGOTIATED
+    self->npn_protocols = NULL;
+#endif
     /* Defaults */
     SSL_CTX_set_verify(self->ctx, SSL_VERIFY_NONE, NULL);
     SSL_CTX_set_options(self->ctx,
@@ -1812,6 +1815,10 @@
     if (!PyArg_ParseTuple(args, "y*:set_npn_protocols", &protos))
         return NULL;
 
+    if (self->npn_protocols != NULL) {
+        PyMem_Free(self->npn_protocols);
+    }
+
     self->npn_protocols = PyMem_Malloc(protos.len);
     if (self->npn_protocols == NULL) {
         PyBuffer_Release(&protos);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list