aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2019-01-07 06:44:29 -0800
committerDoug Hogan <[email protected]>2019-01-07 20:17:55 -0800
commit0a04504f0eee025f02a405ff951f4ff5dea80345 (patch)
treec5496a59b41b9611e5e1f05fdd92166dd4ca5e66
parent5904d78fbea85c481dc595df1e279f068acf6d12 (diff)
downloadotp-0a04504f0eee025f02a405ff951f4ff5dea80345.tar.gz
otp-0a04504f0eee025f02a405ff951f4ff5dea80345.tar.bz2
otp-0a04504f0eee025f02a405ff951f4ff5dea80345.zip
Revamp hmac_context_dtor()
Make it NULL safe.
-rw-r--r--lib/crypto/c_src/hmac.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/crypto/c_src/hmac.c b/lib/crypto/c_src/hmac.c
index 143cde90e1..6ddbd2c59a 100644
--- a/lib/crypto/c_src/hmac.c
+++ b/lib/crypto/c_src/hmac.c
@@ -84,11 +84,17 @@ ERL_NIF_TERM hmac_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
static void hmac_context_dtor(ErlNifEnv* env, struct hmac_context *obj)
{
+ if (obj == NULL)
+ return;
+
if (obj->alive) {
- HMAC_CTX_free(obj->ctx);
+ if (obj->ctx)
+ HMAC_CTX_free(obj->ctx);
obj->alive = 0;
}
- enif_mutex_destroy(obj->mtx);
+
+ if (obj->mtx != NULL)
+ enif_mutex_destroy(obj->mtx);
}
ERL_NIF_TERM hmac_init_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])