mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
In the _hashlib module, only initialize the static data for OpenSSL's
constructors once, to avoid memory leaks when finalizing and re-initializing the Python interpreter.
This commit is contained in:
parent
c0022b2d8c
commit
a8a3468abe
1 changed files with 8 additions and 5 deletions
|
@ -67,7 +67,7 @@ static PyTypeObject EVPtype;
|
||||||
|
|
||||||
|
|
||||||
#define DEFINE_CONSTS_FOR_NEW(Name) \
|
#define DEFINE_CONSTS_FOR_NEW(Name) \
|
||||||
static PyObject *CONST_ ## Name ## _name_obj; \
|
static PyObject *CONST_ ## Name ## _name_obj = NULL; \
|
||||||
static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \
|
static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \
|
||||||
static EVP_MD_CTX *CONST_new_ ## Name ## _ctx_p = NULL;
|
static EVP_MD_CTX *CONST_new_ ## Name ## _ctx_p = NULL;
|
||||||
|
|
||||||
|
@ -525,13 +525,16 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
|
||||||
" hash object; optionally initialized with a string") \
|
" hash object; optionally initialized with a string") \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* used in the init function to setup a constructor */
|
/* used in the init function to setup a constructor: initialize OpenSSL
|
||||||
|
constructor constants if they haven't been initialized already. */
|
||||||
#define INIT_CONSTRUCTOR_CONSTANTS(NAME) do { \
|
#define INIT_CONSTRUCTOR_CONSTANTS(NAME) do { \
|
||||||
|
if (CONST_ ## NAME ## _name_obj == NULL) { \
|
||||||
CONST_ ## NAME ## _name_obj = PyString_FromString(#NAME); \
|
CONST_ ## NAME ## _name_obj = PyString_FromString(#NAME); \
|
||||||
if (EVP_get_digestbyname(#NAME)) { \
|
if (EVP_get_digestbyname(#NAME)) { \
|
||||||
CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \
|
CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \
|
||||||
EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \
|
EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \
|
||||||
} \
|
} \
|
||||||
|
} \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
GEN_CONSTRUCTOR(md5)
|
GEN_CONSTRUCTOR(md5)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue