]> 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 990f4d6c92f963dcd521234ec5bd2f1ea9250bda..63434ba81e40776e9987d8401cb017421efde0ea 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -68,6 +68,9 @@ Library
 Extension Modules
 -----------------
 
+- 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 456b1f1eadbbccd52617aaba6e89a41bddef4573..ad22c5299ce4732f27fa1e8a10a796bede449095 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);