aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/c_src/crypto.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2014-06-19 13:44:11 +0200
committerSverker Eriksson <[email protected]>2014-06-19 13:44:11 +0200
commit1af8998028f77b4ca01c52972a5983b072ef02d1 (patch)
treead902157541bdda70fac3d4769b1a8eeb25c48bc /lib/crypto/c_src/crypto.c
parent42ad82b3186b69fec93ab07ea686490bf2fe5840 (diff)
parent3e04f2d1e62aa76f0ffe4ad36dccd843cc89b9ae (diff)
downloadotp-1af8998028f77b4ca01c52972a5983b072ef02d1.tar.gz
otp-1af8998028f77b4ca01c52972a5983b072ef02d1.tar.bz2
otp-1af8998028f77b4ca01c52972a5983b072ef02d1.zip
Merge branch 'sverk/crypto-ec-mem-leak/OTP-11999' into maint
* sverk/crypto-ec-mem-leak/OTP-11999: crypto: Fix memory leak of EC "keys" and "points" crypto: Fix crypto for debug and valgrind
Diffstat (limited to 'lib/crypto/c_src/crypto.c')
-rw-r--r--lib/crypto/c_src/crypto.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index 6642183cb8..e55a03d26a 100644
--- a/lib/crypto/c_src/crypto.c
+++ b/lib/crypto/c_src/crypto.c
@@ -507,6 +507,15 @@ static int init_ose_crypto() {
#endif
#ifdef HAVE_DYNAMIC_CRYPTO_LIB
+
+# if defined(DEBUG)
+static char crypto_callback_name[] = "crypto_callback.debug";
+# elif defined(VALGRIND)
+static char crypto_callback_name[] = "crypto_callback.valgrind";
+# else
+static char crypto_callback_name[] = "crypto_callback";
+# endif
+
static int change_basename(ErlNifBinary* bin, char* buf, int bufsz, const char* newfile)
{
int i;
@@ -613,7 +622,7 @@ static int init(ErlNifEnv* env, ERL_NIF_TERM load_info)
#ifdef HAVE_DYNAMIC_CRYPTO_LIB
{
void* handle;
- if (!change_basename(&lib_bin, lib_buf, sizeof(lib_buf), "crypto_callback")) {
+ if (!change_basename(&lib_bin, lib_buf, sizeof(lib_buf), crypto_callback_name)) {
return 0;
}
if (!(handle = enif_dlopen(lib_buf, &error_handler, NULL))) {
@@ -3244,6 +3253,7 @@ out:
if (bn_order) BN_free(bn_order);
if (cofactor) BN_free(cofactor);
if (group) EC_GROUP_free(group);
+ if (point) EC_POINT_free(point);
return key;
}
@@ -3406,8 +3416,11 @@ static ERL_NIF_TERM ec_key_generate(ErlNifEnv* env, int argc, const ERL_NIF_TERM
EC_KEY_free(key);
return enif_make_tuple2(env, pub_key, priv_key);
}
- else
+ else {
+ if (key)
+ EC_KEY_free(key);
return enif_make_badarg(env);
+ }
#else
return atom_notsup;
#endif