Commit 1d48f02e authored by Alexander Larsson's avatar Alexander Larsson

Add custom foreach to eel_g_hash_table_new_free_at_exit

This can be used to get some sort of printout for leaks in non-string
hashtables.
parent 1a8aadd2
......@@ -48,7 +48,7 @@
typedef struct {
GHashTable *hash_table;
char *display_name;
gboolean keys_known_to_be_strings;
GHFunc foreach_func;
} HashTableToFree;
static GList *hash_tables_to_free_at_exit;
......@@ -533,16 +533,16 @@ free_hash_tables_at_exit (void)
size = g_hash_table_size (hash_table_to_free->hash_table);
if (size != 0) {
if (hash_table_to_free->keys_known_to_be_strings) {
if (hash_table_to_free->foreach_func) {
g_print ("\n--- Hash table keys for warning below:\n");
g_hash_table_foreach (hash_table_to_free->hash_table,
print_key_string,
hash_table_to_free->foreach_func,
NULL);
}
g_warning ("\"%s\" hash table still has %u element%s at quit time%s",
hash_table_to_free->display_name, size,
size == 1 ? "" : "s",
hash_table_to_free->keys_known_to_be_strings
hash_table_to_free->foreach_func
? " (keys above)" : "");
}
......@@ -557,6 +557,7 @@ free_hash_tables_at_exit (void)
GHashTable *
eel_g_hash_table_new_free_at_exit (GHashFunc hash_func,
GCompareFunc key_compare_func,
GHFunc foreach_func,
const char *display_name)
{
GHashTable *hash_table;
......@@ -575,8 +576,11 @@ eel_g_hash_table_new_free_at_exit (GHashFunc hash_func,
hash_table_to_free = g_new (HashTableToFree, 1);
hash_table_to_free->hash_table = hash_table;
hash_table_to_free->display_name = g_strdup (display_name);
hash_table_to_free->keys_known_to_be_strings =
hash_func == g_str_hash;
hash_table_to_free->foreach_func = foreach_func;
if (hash_table_to_free->foreach_func == NULL &&
hash_func == g_str_hash) {
hash_table_to_free->foreach_func = print_key_string;
}
hash_tables_to_free_at_exit = g_list_prepend
(hash_tables_to_free_at_exit, hash_table_to_free);
......
......@@ -69,6 +69,7 @@ GList * eel_g_object_list_copy (GList *
/* GHashTable functions */
GHashTable *eel_g_hash_table_new_free_at_exit (GHashFunc hash_function,
GCompareFunc key_compare_function,
GHFunc foreach_func,
const char *display_name);
void eel_g_hash_table_safe_for_each (GHashTable *hash_table,
GHFunc callback,
......
......@@ -272,7 +272,7 @@ eel_timed_wait_start_with_duration (int duration,
/* Put in the hash table so we can find it later. */
if (timed_wait_hash_table == NULL) {
timed_wait_hash_table = eel_g_hash_table_new_free_at_exit
(timed_wait_hash, timed_wait_hash_equal, __FILE__ ": timed wait");
(timed_wait_hash, timed_wait_hash_equal, NULL, __FILE__ ": timed wait");
}
g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == NULL);
g_hash_table_insert (timed_wait_hash_table, wait, wait);
......
......@@ -855,7 +855,7 @@ eel_ref_str_get_unique (const char *string)
if (unique_ref_strs == NULL) {
unique_ref_strs =
eel_g_hash_table_new_free_at_exit (g_str_hash, g_str_equal,
"unique eel_ref_str");
NULL, "unique eel_ref_str");
}
res = g_hash_table_lookup (unique_ref_strs, string);
......
......@@ -365,7 +365,7 @@ async_job_start (NautilusDirectory *directory,
if (async_job_count >= MAX_ASYNC_JOBS) {
if (waiting_directories == NULL) {
waiting_directories = eel_g_hash_table_new_free_at_exit
(NULL, NULL,
(NULL, NULL, NULL,
"nautilus-directory-async.c: waiting_directories");
}
......@@ -381,7 +381,7 @@ async_job_start (NautilusDirectory *directory,
char *uri;
if (async_jobs == NULL) {
async_jobs = eel_g_hash_table_new_free_at_exit
(g_str_hash, g_str_equal,
(g_str_hash, g_str_equal, NULL,
"nautilus-directory-async.c: async_jobs");
}
uri = nautilus_directory_get_uri (directory);
......
......@@ -348,7 +348,8 @@ nautilus_directory_get_internal (GFile *location, gboolean create)
/* Create the hash table first time through. */
if (directories == NULL) {
directories = eel_g_hash_table_new_free_at_exit
(g_file_hash, (GCompareFunc)g_file_equal, "nautilus-directory.c: directories");
(g_file_hash, (GCompareFunc)g_file_equal, NULL,
"nautilus-directory.c: directories");
add_preferences_callbacks ();
}
......
......@@ -550,7 +550,7 @@ modify_link_hash_table (NautilusFile *file,
/* Create the hash table first time through. */
if (symbolic_links == NULL) {
symbolic_links = eel_g_hash_table_new_free_at_exit
(g_str_hash, g_str_equal, "nautilus-file.c: symbolic_links");
(g_str_hash, g_str_equal, NULL, "nautilus-file.c: symbolic_links");
}
target_uri = nautilus_file_get_symbolic_link_target_uri (file);
......
......@@ -5087,12 +5087,12 @@ nautilus_properties_window_present (GList *original_files,
/* Create the hash tables first time through. */
if (windows == NULL) {
windows = eel_g_hash_table_new_free_at_exit
(NULL, NULL, "property windows");
(NULL, NULL, NULL, "property windows");
}
if (pending_lists == NULL) {
pending_lists = eel_g_hash_table_new_free_at_exit
(g_str_hash, g_str_equal, "pending property window files");
(g_str_hash, g_str_equal, NULL, "pending property window files");
}
/* Look to see if there's already a window for this file. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment