diff options
author | jsing <> | 2017-05-06 20:59:28 +0000 |
---|---|---|
committer | jsing <> | 2017-05-06 20:59:28 +0000 |
commit | 7d324d6b4a253e59f811b823131fa480dca49d94 (patch) | |
tree | 657a8c245abd0d5e2045521716d7977e1dfe887f /src/lib/libtls/tls_config.c | |
parent | e09c50ecb0edf1f7c4f6a7b1dee1285ccbf08d5a (diff) | |
download | openbsd-7d324d6b4a253e59f811b823131fa480dca49d94.tar.gz openbsd-7d324d6b4a253e59f811b823131fa480dca49d94.tar.bz2 openbsd-7d324d6b4a253e59f811b823131fa480dca49d94.zip |
Perform reference counting for tls_config. This allows tls_config_free() to
be called as soon as it has been passed to the final tls_configure() call,
simplifying lifetime tracking for the application.
Requested some time ago by tedu@.
ok beck@
Diffstat (limited to 'src/lib/libtls/tls_config.c')
-rw-r--r-- | src/lib/libtls/tls_config.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/lib/libtls/tls_config.c b/src/lib/libtls/tls_config.c index 3945da75ac..8f0bd70508 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.39 2017/05/02 03:59:45 deraadt Exp $ */ | 1 | /* $OpenBSD: tls_config.c,v 1.40 2017/05/06 20:59:28 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -207,6 +207,8 @@ tls_config_new(void) | |||
207 | if ((config->keypair = tls_keypair_new()) == NULL) | 207 | if ((config->keypair = tls_keypair_new()) == NULL) |
208 | goto err; | 208 | goto err; |
209 | 209 | ||
210 | config->refcount = 1; | ||
211 | |||
210 | /* | 212 | /* |
211 | * Default configuration. | 213 | * Default configuration. |
212 | */ | 214 | */ |
@@ -252,6 +254,9 @@ tls_config_free(struct tls_config *config) | |||
252 | if (config == NULL) | 254 | if (config == NULL) |
253 | return; | 255 | return; |
254 | 256 | ||
257 | if (--config->refcount > 0) | ||
258 | return; | ||
259 | |||
255 | for (kp = config->keypair; kp != NULL; kp = nkp) { | 260 | for (kp = config->keypair; kp != NULL; kp = nkp) { |
256 | nkp = kp->next; | 261 | nkp = kp->next; |
257 | tls_keypair_free(kp); | 262 | tls_keypair_free(kp); |