aboutsummaryrefslogtreecommitdiffstats
path: root/src/libtnccs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtnccs')
-rw-r--r--src/libtnccs/tnc/tnc.c18
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;
}