diff options
author | Gregory P. Smith <greg@krypto.org> | 2013-02-02 01:07:39 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2013-02-02 01:07:39 (GMT) |
commit | 90fa9508a6c1cc862de002c2a35b8abe1c5eb42d (patch) | |
tree | 068a0b194ca6aea254f33f66ec76ecbe762c6de7 | |
parent | b2da96b3bbc40d7fbeb3208a59c28db4f5783e10 (diff) | |
parent | aded2e5e59a122962ccbf8058cd306da344f27b9 (diff) | |
download | cpython-90fa9508a6c1cc862de002c2a35b8abe1c5eb42d.zip cpython-90fa9508a6c1cc862de002c2a35b8abe1c5eb42d.tar.gz cpython-90fa9508a6c1cc862de002c2a35b8abe1c5eb42d.tar.bz2 |
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.
-rw-r--r-- | Modules/_hashopenssl.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index d37689e..3ab1c0c 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -70,7 +70,7 @@ static PyTypeObject EVPtype; #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_p = NULL; @@ -585,12 +585,15 @@ generate_hash_name_list(void) " 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 { \ - CONST_ ## NAME ## _name_obj = PyUnicode_FromString(#NAME); \ - if (EVP_get_digestbyname(#NAME)) { \ - CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \ - EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \ + if (CONST_ ## NAME ## _name_obj == NULL) { \ + CONST_ ## NAME ## _name_obj = PyUnicode_FromString(#NAME); \ + if (EVP_get_digestbyname(#NAME)) { \ + CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \ + EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \ + } \ } \ } while (0); |