diff options
author | Martin Willi <martin@revosec.ch> | 2012-10-25 15:23:49 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-11-14 10:14:40 +0100 |
commit | 07474b6062e1bbed3be41e6d5f7ac9795e281920 (patch) | |
tree | 2db83fa8506454c8d01e51bc817bd2d2b108f1ae /src/libtnccs | |
parent | de4c1def83431a38395511f7e006218b3112b4b1 (diff) | |
download | strongswan-07474b6062e1bbed3be41e6d5f7ac9795e281920.tar.bz2 strongswan-07474b6062e1bbed3be41e6d5f7ac9795e281920.tar.xz |
libtnc can be initialized more than once
Diffstat (limited to 'src/libtnccs')
-rw-r--r-- | src/libtnccs/tnc/tnc.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libtnccs/tnc/tnc.c b/src/libtnccs/tnc/tnc.c index feded3b2c..728d2b28d 100644 --- a/src/libtnccs/tnc/tnc.c +++ b/src/libtnccs/tnc/tnc.c @@ -40,6 +40,11 @@ struct private_tnc_t { * Public members of tnc_t. */ tnc_t public; + + /** + * Number of times we have been initialized + */ + refcount_t ref; }; /** @@ -54,9 +59,17 @@ void libtnccs_init(void) { private_tnc_t *this; + if (tnc) + { /* already initialized, increase refcount */ + this = (private_tnc_t*)tnc; + ref_get(&this->ref); + return; + } + INIT(this, .public = { }, + .ref = 1, ); tnc = &this->public; @@ -69,6 +82,11 @@ void libtnccs_deinit(void) { private_tnc_t *this = (private_tnc_t*)tnc; + if (!this || !ref_put(&this->ref)) + { /* have more users */ + return; + } + free(this); tnc = NULL; } |