]> granicus.if.org Git - python/commitdiff
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols...
authorChristian Heimes <christian@cheimes.de>
Thu, 20 Sep 2012 10:42:54 +0000 (12:42 +0200)
committerChristian Heimes <christian@cheimes.de>
Thu, 20 Sep 2012 10:42:54 +0000 (12:42 +0200)
Misc/NEWS
Modules/_ssl.c

index 96e5fdd722351b2cb4cabab621aa0153a5c06b4a..04bc41d953be559d9bd10069f072030597f65ebd 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -201,6 +201,9 @@ Documentation
 - 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
 -----
 
index 1104a4eab789211c82b6474afbd5e49d7602e2c2..1516b87e2eba8ca0e31297244396bd29b71779b5 100644 (file)
@@ -1713,6 +1713,9 @@ context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
         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 @@ _set_npn_protocols(PySSLContext *self, PyObject *args)
     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);