Introduce our own shutdown callback mechanism.
Instead of adding stuff to `_shutdown()`, we can now register a shutdown routine from the respective `init()` function of our modules. This also has the advantage, that we're sure they're called in reverse order from how the initialization happened. I didn't simply use `atexit()` because POSIX says that the number of possible callbacks is limited (min 32) and I was not sure whether we will maybe extend this number at one point. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -166,12 +166,24 @@ otr_start_query(void)
|
||||
return otrlib_start_query();
|
||||
}
|
||||
|
||||
static void
|
||||
_otr_shutdown(void)
|
||||
{
|
||||
if (jid) {
|
||||
free(jid);
|
||||
jid = NULL;
|
||||
}
|
||||
otrlib_shutdown();
|
||||
}
|
||||
|
||||
void
|
||||
otr_init(void)
|
||||
{
|
||||
log_info("Initialising OTR");
|
||||
OTRL_INIT;
|
||||
|
||||
prof_add_shutdown_routine(_otr_shutdown);
|
||||
|
||||
jid = NULL;
|
||||
|
||||
ops.policy = cb_policy;
|
||||
@@ -187,16 +199,6 @@ otr_init(void)
|
||||
data_loaded = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
otr_shutdown(void)
|
||||
{
|
||||
if (jid) {
|
||||
free(jid);
|
||||
jid = NULL;
|
||||
}
|
||||
otrlib_shutdown();
|
||||
}
|
||||
|
||||
void
|
||||
otr_poll(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user