mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Free plugins on shutdown
This commit is contained in:
parent
913fcde3ae
commit
1ed339f82b
@ -135,17 +135,21 @@ c_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *m
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
c_plugin_destroy(ProfPlugin *plugin)
|
||||
{
|
||||
assert (plugin && plugin->module);
|
||||
|
||||
if (dlclose (plugin->module)) {
|
||||
log_warning ("dlclose failed to close `%s' with `%s'", plugin->name, dlerror ());
|
||||
}
|
||||
|
||||
free(plugin->name);
|
||||
free(plugin);
|
||||
}
|
||||
|
||||
void
|
||||
c_shutdown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
c_close_library (ProfPlugin * plugin)
|
||||
{
|
||||
assert (plugin && plugin->module);
|
||||
|
||||
if (dlclose (plugin->module))
|
||||
log_warning ("dlclose failed to close `%s' with `%s'", plugin->name, dlerror ());
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ void c_on_start_hook (ProfPlugin *plugin);
|
||||
void c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
||||
char * c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
char * c_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
void c_close_library (ProfPlugin * plugin);
|
||||
void c_plugin_destroy(ProfPlugin * plugin);
|
||||
|
||||
void c_shutdown(void);
|
||||
|
||||
#endif
|
||||
|
@ -160,21 +160,22 @@ plugins_shutdown(void)
|
||||
{
|
||||
GSList *curr = plugins;
|
||||
|
||||
python_shutdown();
|
||||
ruby_shutdown();
|
||||
c_shutdown();
|
||||
|
||||
//FIXME do we need to clean the plugins list?
|
||||
//for the time being I'll just call dlclose for
|
||||
//every C plugin.
|
||||
|
||||
while (curr != NULL) {
|
||||
ProfPlugin *plugin = curr->data;
|
||||
if (plugin->lang == LANG_C)
|
||||
c_close_library (plugin);
|
||||
if (plugin->lang == LANG_C) {
|
||||
c_plugin_destroy(plugin);
|
||||
} else if (plugin->lang == LANG_PYTHON) {
|
||||
python_plugin_destroy(plugin);
|
||||
} else if (plugin->lang == LANG_RUBY) {
|
||||
ruby_plugin_destroy(plugin);
|
||||
}
|
||||
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
python_shutdown();
|
||||
ruby_shutdown();
|
||||
c_shutdown();
|
||||
}
|
||||
|
||||
gchar *
|
||||
|
@ -57,7 +57,7 @@ python_plugin_create(const char * const filename)
|
||||
python_check_error();
|
||||
if (p_module != NULL) {
|
||||
ProfPlugin *plugin = malloc(sizeof(ProfPlugin));
|
||||
plugin->name = module_name;
|
||||
plugin->name = strdup(module_name);
|
||||
plugin->lang = LANG_PYTHON;
|
||||
plugin->module = p_module;
|
||||
plugin->init_func = python_init_hook;
|
||||
@ -192,6 +192,14 @@ python_check_error(void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
python_plugin_destroy(ProfPlugin *plugin)
|
||||
{
|
||||
free(plugin->name);
|
||||
Py_XDECREF(plugin->module);
|
||||
free(plugin);
|
||||
}
|
||||
|
||||
void
|
||||
python_shutdown(void)
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ void python_on_connect_hook(ProfPlugin *plugin, const char * const account_name,
|
||||
char * python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
char * python_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
|
||||
void python_plugin_destroy(ProfPlugin *plugin);
|
||||
void python_check_error(void);
|
||||
|
||||
#endif
|
||||
|
@ -54,7 +54,7 @@ ruby_plugin_create(const char * const filename)
|
||||
ruby_check_error();
|
||||
|
||||
ProfPlugin *plugin = malloc(sizeof(ProfPlugin));
|
||||
plugin->name = module_name;
|
||||
plugin->name = strdup(module_name);
|
||||
plugin->lang = LANG_RUBY;
|
||||
plugin->module = (void *)rb_const_get(rb_cObject, rb_intern(module_name));
|
||||
plugin->init_func = ruby_init_hook;
|
||||
@ -62,6 +62,7 @@ ruby_plugin_create(const char * const filename)
|
||||
plugin->on_connect_func = ruby_on_connect_hook;
|
||||
plugin->on_message_received_func = ruby_on_message_received_hook;
|
||||
plugin->on_message_send_func = ruby_on_message_send_hook;
|
||||
g_free(module_name);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@ -147,6 +148,13 @@ ruby_check_error(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ruby_plugin_destroy(ProfPlugin *plugin)
|
||||
{
|
||||
free(plugin->name);
|
||||
free(plugin);
|
||||
}
|
||||
|
||||
void
|
||||
ruby_shutdown(void)
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ void ruby_on_connect_hook(ProfPlugin *plugin, const char * const account_name, c
|
||||
char * ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
char * ruby_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
|
||||
void ruby_plugin_destroy(ProfPlugin *plugin);
|
||||
void ruby_check_error(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user