Kaydet (Commit) 5cb31c92 authored tarafından Christian Heimes's avatar Christian Heimes

Issue #15977: Fix memory leak in Modules/_ssl.c when the function…

Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
üst 4a5fae1b
...@@ -68,6 +68,9 @@ Library ...@@ -68,6 +68,9 @@ Library
Extension Modules 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 Tests
----- -----
......
...@@ -1713,6 +1713,9 @@ context_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -1713,6 +1713,9 @@ context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL; return NULL;
} }
self->ctx = ctx; self->ctx = ctx;
#ifdef OPENSSL_NPN_NEGOTIATED
self->npn_protocols = NULL;
#endif
/* Defaults */ /* Defaults */
SSL_CTX_set_verify(self->ctx, SSL_VERIFY_NONE, NULL); SSL_CTX_set_verify(self->ctx, SSL_VERIFY_NONE, NULL);
SSL_CTX_set_options(self->ctx, SSL_CTX_set_options(self->ctx,
...@@ -1812,6 +1815,10 @@ _set_npn_protocols(PySSLContext *self, PyObject *args) ...@@ -1812,6 +1815,10 @@ _set_npn_protocols(PySSLContext *self, PyObject *args)
if (!PyArg_ParseTuple(args, "y*:set_npn_protocols", &protos)) if (!PyArg_ParseTuple(args, "y*:set_npn_protocols", &protos))
return NULL; return NULL;
if (self->npn_protocols != NULL) {
PyMem_Free(self->npn_protocols);
}
self->npn_protocols = PyMem_Malloc(protos.len); self->npn_protocols = PyMem_Malloc(protos.len);
if (self->npn_protocols == NULL) { if (self->npn_protocols == NULL) {
PyBuffer_Release(&protos); PyBuffer_Release(&protos);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment