* #25241: gnome: dlclose and free addressbook when exiting

This commit is contained in:
Tristan Matthews
2013-05-31 11:35:53 -04:00
parent 02db63c1ce
commit 4a007f5eaf
4 changed files with 23 additions and 2 deletions

View File

@ -158,6 +158,8 @@ sflphone_quit(gboolean force_quit, SFLPhoneClient *client)
calllist_clean(current_calls_tab);
calllist_clean(contacts_tab);
calllist_clean(history_tab);
free_addressbook();
#if GLIB_CHECK_VERSION(2,32,0)
g_application_quit(G_APPLICATION(client));
#else

View File

@ -84,21 +84,26 @@ handler_async_search(GList *hits, gpointer user_data)
void abook_init()
{
/* Clear any existing error */
dlerror();
const gchar *addrbook_path = PLUGINS_DIR "/libevladdrbook.so";
/* FIXME: handle should be unloaded with dlclose on exit */
void *handle = dlopen(addrbook_path, RTLD_LAZY);
if (handle == NULL) {
g_debug("Did not load addressbook from path %s", addrbook_path);
g_debug("Did not load addressbook from path %s:%s", addrbook_path, dlerror());
return;
}
addrbook = g_new0(AddrBookHandle, 1);
/* Keep the handle around to dlclose it later */
addrbook->handle = handle;
#define LOAD(func) do { \
addrbook-> func = dlsym(handle, "addressbook_" #func); \
if (addrbook-> func == NULL) { \
g_warning("Couldn't load " # func); \
g_warning("Couldn't load " # func ":%s", dlerror());\
dlclose(handle); \
g_free(addrbook); \
addrbook = NULL; \
@ -118,3 +123,15 @@ void abook_init()
addrbook->search_cb = handler_async_search;
}
void
free_addressbook()
{
if (!addrbook)
return;
if (addrbook->handle)
dlclose(addrbook->handle);
g_free(addrbook);
}

View File

@ -35,6 +35,7 @@
#include "addressbook.h"
void abook_init();
void free_addressbook();
extern AddrBookHandle *addrbook;

View File

@ -86,6 +86,7 @@ struct AddrBookHandle {
void (*set_current_book)(const gchar *);
void (*set_search_type)(AddrbookSearchType);
void (*search_cb)(GList *, gpointer);
void *handle;
};
#endif