diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libtls/tls_config.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lib/libtls/tls_config.c b/src/lib/libtls/tls_config.c index 19dcc8b0d0..62361e6122 100644 --- a/src/lib/libtls/tls_config.c +++ b/src/lib/libtls/tls_config.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls_config.c,v 1.54 2019/03/27 11:12:10 tedu Exp $ */ | 1 | /* $OpenBSD: tls_config.c,v 1.55 2019/04/01 15:58:02 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -20,6 +20,7 @@ | |||
20 | #include <ctype.h> | 20 | #include <ctype.h> |
21 | #include <errno.h> | 21 | #include <errno.h> |
22 | #include <fcntl.h> | 22 | #include <fcntl.h> |
23 | #include <pthread.h> | ||
23 | #include <stdlib.h> | 24 | #include <stdlib.h> |
24 | #include <unistd.h> | 25 | #include <unistd.h> |
25 | 26 | ||
@@ -96,6 +97,7 @@ tls_config_new_internal(void) | |||
96 | if ((config->keypair = tls_keypair_new()) == NULL) | 97 | if ((config->keypair = tls_keypair_new()) == NULL) |
97 | goto err; | 98 | goto err; |
98 | 99 | ||
100 | config->mutex = PTHREAD_MUTEX_INITIALIZER; | ||
99 | config->refcount = 1; | 101 | config->refcount = 1; |
100 | config->session_fd = -1; | 102 | config->session_fd = -1; |
101 | 103 | ||
@@ -149,11 +151,16 @@ void | |||
149 | tls_config_free(struct tls_config *config) | 151 | tls_config_free(struct tls_config *config) |
150 | { | 152 | { |
151 | struct tls_keypair *kp, *nkp; | 153 | struct tls_keypair *kp, *nkp; |
154 | int refcount; | ||
152 | 155 | ||
153 | if (config == NULL) | 156 | if (config == NULL) |
154 | return; | 157 | return; |
155 | 158 | ||
156 | if (--config->refcount > 0) | 159 | pthread_mutex_lock(&config->mutex); |
160 | refcount = --config->refcount; | ||
161 | pthread_mutex_unlock(&config->mutex); | ||
162 | |||
163 | if (refcount > 0) | ||
157 | return; | 164 | return; |
158 | 165 | ||
159 | for (kp = config->keypair; kp != NULL; kp = nkp) { | 166 | for (kp = config->keypair; kp != NULL; kp = nkp) { |