libtnc can be initialized more than once
This commit is contained in:
parent
de4c1def83
commit
07474b6062
|
@ -40,6 +40,11 @@ struct private_tnc_t {
|
||||||
* Public members of tnc_t.
|
* Public members of tnc_t.
|
||||||
*/
|
*/
|
||||||
tnc_t public;
|
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;
|
private_tnc_t *this;
|
||||||
|
|
||||||
|
if (tnc)
|
||||||
|
{ /* already initialized, increase refcount */
|
||||||
|
this = (private_tnc_t*)tnc;
|
||||||
|
ref_get(&this->ref);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
INIT(this,
|
INIT(this,
|
||||||
.public = {
|
.public = {
|
||||||
},
|
},
|
||||||
|
.ref = 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
tnc = &this->public;
|
tnc = &this->public;
|
||||||
|
@ -69,6 +82,11 @@ void libtnccs_deinit(void)
|
||||||
{
|
{
|
||||||
private_tnc_t *this = (private_tnc_t*)tnc;
|
private_tnc_t *this = (private_tnc_t*)tnc;
|
||||||
|
|
||||||
|
if (!this || !ref_put(&this->ref))
|
||||||
|
{ /* have more users */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
free(this);
|
free(this);
|
||||||
tnc = NULL;
|
tnc = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue