diff --git a/desktop/cookies.c b/desktop/cookies.c index e22dcc289..a49a8db9f 100644 --- a/desktop/cookies.c +++ b/desktop/cookies.c @@ -432,6 +432,8 @@ void cookies_remove(const struct cookie_data *data) */ void cookies_cleanup(void) { + hlcache_handle_release(folder_icon); + hlcache_handle_release(cookie_icon); } /* Actions to be connected to front end specific toolbars */ diff --git a/desktop/history_global_core.c b/desktop/history_global_core.c index 771928467..8c8834834 100644 --- a/desktop/history_global_core.c +++ b/desktop/history_global_core.c @@ -317,6 +317,8 @@ unsigned int history_global_get_tree_flags(void) */ void history_global_cleanup(void) { + hlcache_handle_release(folder_icon); + tree_url_node_cleanup(); } diff --git a/desktop/hotlist.c b/desktop/hotlist.c index dd29b6a84..a740458cb 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -205,6 +205,8 @@ unsigned int hotlist_get_tree_flags(void) void hotlist_cleanup(const char *hotlist_path) { hotlist_export(hotlist_path); + hlcache_handle_release(folder_icon); + tree_url_node_cleanup(); } diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 1b2b16e62..fc51a99e0 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -40,6 +40,7 @@ #include "desktop/browser.h" #include "desktop/gui.h" #include "desktop/options.h" +#include "desktop/searchweb.h" #include "utils/log.h" #include "utils/url.h" #include "utils/utf8.h" @@ -176,6 +177,8 @@ void netsurf_exit(void) { LOG(("Closing GUI")); gui_quit(); + LOG(("Closing search and related resources")); + search_web_cleanup(); LOG(("Finalising high-level cache")); hlcache_finalise(); LOG(("Finalising low-level cache")); diff --git a/desktop/searchweb.c b/desktop/searchweb.c index 6c86eef5b..fc04e68b6 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -267,6 +267,17 @@ hlcache_handle *search_web_ico(void) return search_ico; } +/** + * Cleans up any remaining resources during shutdown. + */ +void search_web_cleanup(void) +{ + if (search_ico != NULL) { + hlcache_handle_release(search_ico); + search_ico = NULL; + } +} + /** * callback function to cache ico then notify front when successful * else retry default from local file system diff --git a/desktop/searchweb.h b/desktop/searchweb.h index 6cc23036a..3920f3c6e 100644 --- a/desktop/searchweb.h +++ b/desktop/searchweb.h @@ -75,4 +75,6 @@ void search_web_retrieve_ico(bool localdefault); struct hlcache_handle *search_web_ico(void); +void search_web_cleanup(void); + #endif diff --git a/desktop/sslcert.c b/desktop/sslcert.c index 9aff25700..e247b0bd0 100644 --- a/desktop/sslcert.c +++ b/desktop/sslcert.c @@ -78,6 +78,7 @@ unsigned int sslcert_get_tree_flags(void) void sslcert_cleanup(void) { + hlcache_handle_release(sslcert_icon); return; } diff --git a/desktop/tree_url_node.c b/desktop/tree_url_node.c index 182c9332d..76138a147 100644 --- a/desktop/tree_url_node.c +++ b/desktop/tree_url_node.c @@ -102,12 +102,15 @@ struct icon_entry icon_table[] = { {CONTENT_HTML, NULL} }; +static uint32_t tun_users = 0; void tree_url_node_init(const char *folder_icon_name) { struct icon_entry *entry; char icon_name[MAX_ICON_NAME_LEN]; - + + tun_users++; + if (initialised || option_tree_icons_dir == NULL) return; initialised = true; @@ -122,10 +125,31 @@ void tree_url_node_init(const char *folder_icon_name) ++entry; } while (entry->type != CONTENT_HTML); - } +void tree_url_node_cleanup() +{ + struct icon_entry *entry; + + tun_users--; + + if (tun_users > 0) + return; + + if (!initialised) + return; + initialised = false; + + hlcache_handle_release(folder_icon); + + entry = icon_table; + do { + hlcache_handle_release(entry->icon); + ++entry; + } while (entry->type != CONTENT_HTML); +} + /** * Creates a tree entry for a URL, and links it into the tree * diff --git a/desktop/tree_url_node.h b/desktop/tree_url_node.h index fbecf7f28..6d62895e4 100644 --- a/desktop/tree_url_node.h +++ b/desktop/tree_url_node.h @@ -28,6 +28,7 @@ #include "desktop/tree.h" void tree_url_node_init(const char *folder_icon_name); +void tree_url_node_cleanup(void); struct node *tree_create_URL_node(struct tree *tree, struct node *parent, const char *url, const char *title, tree_node_user_callback, void *callback_data);