mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
This commit is contained in:
parent
4a5fae1b79
commit
5cb31c9277
2 changed files with 10 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue