summaryrefslogtreecommitdiff
path: root/lib/libtls/tls.c
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2018-02-08 08:04:13 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2018-02-08 08:04:13 +0000
commitcaf6db16c1c7f3cb62f9b38f0cc5e5c4985a87d5 (patch)
tree87cf1cd8841663473c59d304af140fa77e1c339f /lib/libtls/tls.c
parentbc4d521c3a9bcaa8c4c2b26b0b08c307856b5280 (diff)
Avoid a memory leak that results when the same tls_config is reused.
Reported by and fix from Nate Bessette <openbsd at nate dot sh> - thanks.
Diffstat (limited to 'lib/libtls/tls.c')
-rw-r--r--lib/libtls/tls.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/libtls/tls.c b/lib/libtls/tls.c
index f07c4c6deb0..95fdb8bc4b9 100644
--- a/lib/libtls/tls.c
+++ b/lib/libtls/tls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls.c,v 1.71 2017/09/20 17:05:17 jsing Exp $ */
+/* $OpenBSD: tls.c,v 1.72 2018/02/08 08:04:12 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -269,7 +269,9 @@ tls_cert_hash(X509 *cert, char **hash)
char d[EVP_MAX_MD_SIZE], *dhex = NULL;
int dlen, rv = -1;
+ free(*hash);
*hash = NULL;
+
if (X509_digest(cert, EVP_sha256(), d, &dlen) != 1)
goto err;
@@ -296,6 +298,7 @@ tls_keypair_pubkey_hash(struct tls_keypair *keypair, char **hash)
char d[EVP_MAX_MD_SIZE], *dhex = NULL;
int dlen, rv = -1;
+ free(*hash);
*hash = NULL;
if ((membio = BIO_new_mem_buf(keypair->cert_mem,