[nautilus] all: remove eel_g_hash_table_new_free_at_exit()



commit 0d46b0620b3b120cde310cb2319c309d8f3e3b82
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Mar 7 21:04:51 2012 -0500

    all: remove eel_g_hash_table_new_free_at_exit()
    
    Especially when references can be owned by non-resident modules, this is
    just too dangerous.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=670989

 eel/eel-glib-extensions.c                      |   83 ------------------------
 eel/eel-glib-extensions.h                      |    4 -
 eel/eel-stock-dialogs.c                        |    3 +-
 eel/eel-string.c                               |    3 +-
 libnautilus-private/nautilus-directory-async.c |    8 +--
 libnautilus-private/nautilus-directory.c       |   15 +----
 libnautilus-private/nautilus-file.c            |    3 +-
 libnautilus-private/nautilus-signaller.c       |    1 -
 libnautilus-private/nautilus-thumbnails.c      |    2 -
 src/nautilus-properties-window.c               |    6 +-
 10 files changed, 8 insertions(+), 120 deletions(-)
---
diff --git a/eel/eel-glib-extensions.c b/eel/eel-glib-extensions.c
index d6fee1a..ed9e222 100644
--- a/eel/eel-glib-extensions.c
+++ b/eel/eel-glib-extensions.c
@@ -45,14 +45,6 @@
 
 #define SAFE_SHELL_CHARACTERS "-_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
 
-typedef struct {
-	GHashTable *hash_table;
-	char *display_name;
-	GHFunc foreach_func;
-} HashTableToFree;
-
-static GList *hash_tables_to_free_at_exit;
-
 /**
  * eel_g_date_new_tm:
  * 
@@ -513,81 +505,6 @@ eel_get_system_time (void)
 	return (gint64)tmp.tv_usec + (gint64)tmp.tv_sec * G_GINT64_CONSTANT (1000000);
 }
 
-static void
-print_key_string (gpointer key, gpointer value, gpointer callback_data)
-{
-	g_assert (callback_data == NULL);
-
-	g_print ("--> %s\n", (char *) key);
-}
-
-static void
-free_hash_tables_at_exit (void)
-{
-	GList *p;
-	HashTableToFree *hash_table_to_free;
-	guint size;
-
-	for (p = hash_tables_to_free_at_exit; p != NULL; p = p->next) {
-		hash_table_to_free = p->data;
-
-		size = g_hash_table_size (hash_table_to_free->hash_table);
-		if (size != 0) {
-			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,
-						      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->foreach_func
-				   ? " (keys above)" : "");
-		}
-
-		g_hash_table_destroy (hash_table_to_free->hash_table);
-		g_free (hash_table_to_free->display_name);
-		g_free (hash_table_to_free);
-	}
-	g_list_free (hash_tables_to_free_at_exit);
-	hash_tables_to_free_at_exit = NULL;
-}
-
-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;
-	HashTableToFree *hash_table_to_free;
-
-	/* FIXME: We can take out the NAUTILUS_DEBUG check once we
-	 * have fixed more of the leaks. For now, it's a bit too noisy
-	 * for the general public.
-	 */
-	if (hash_tables_to_free_at_exit == NULL) {
-		eel_debug_call_at_shutdown (free_hash_tables_at_exit);
-	}
-
-	hash_table = g_hash_table_new (hash_func, key_compare_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->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);
-
-	return hash_table;
-}
-
 typedef struct {
 	GList *keys;
 	GList *values;
diff --git a/eel/eel-glib-extensions.h b/eel/eel-glib-extensions.h
index 6812f8d..d32f880 100644
--- a/eel/eel-glib-extensions.h
+++ b/eel/eel-glib-extensions.h
@@ -67,10 +67,6 @@ GList *     eel_g_object_list_ref                       (GList                 *
 GList *     eel_g_object_list_copy                      (GList                 *list);
 
 /* 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,
 							 gpointer               callback_data);
diff --git a/eel/eel-stock-dialogs.c b/eel/eel-stock-dialogs.c
index fe29ef8..bc5bb29 100644
--- a/eel/eel-stock-dialogs.c
+++ b/eel/eel-stock-dialogs.c
@@ -271,8 +271,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, NULL, __FILE__ ": timed wait");
+		timed_wait_hash_table = g_hash_table_new (timed_wait_hash, timed_wait_hash_equal);
 	}
 	g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == NULL);
 	g_hash_table_insert (timed_wait_hash_table, wait, wait);
diff --git a/eel/eel-string.c b/eel/eel-string.c
index 3d6f9d3..3ecd9f2 100644
--- a/eel/eel-string.c
+++ b/eel/eel-string.c
@@ -656,8 +656,7 @@ eel_ref_str_get_unique (const char *string)
 	G_LOCK (unique_ref_strs);
 	if (unique_ref_strs == NULL) {
 		unique_ref_strs =
-			eel_g_hash_table_new_free_at_exit (g_str_hash, g_str_equal,
-							   NULL, "unique eel_ref_str");
+			g_hash_table_new (g_str_hash, g_str_equal);
 	}
 
 	res = g_hash_table_lookup (unique_ref_strs, string);
diff --git a/libnautilus-private/nautilus-directory-async.c b/libnautilus-private/nautilus-directory-async.c
index 98fdaf8..852c6ed 100644
--- a/libnautilus-private/nautilus-directory-async.c
+++ b/libnautilus-private/nautilus-directory-async.c
@@ -363,9 +363,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,
-				 "nautilus-directory-async.c: waiting_directories");
+			waiting_directories = g_hash_table_new (NULL, NULL);
 		}
 
 		g_hash_table_insert (waiting_directories,
@@ -379,9 +377,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, NULL,
-				 "nautilus-directory-async.c: async_jobs");
+			async_jobs = g_hash_table_new (g_str_hash, g_str_equal);
 		}
 		uri = nautilus_directory_get_uri (directory);
 		key = g_strconcat (uri, ": ", job, NULL);
diff --git a/libnautilus-private/nautilus-directory.c b/libnautilus-private/nautilus-directory.c
index 9038b49..f69ece7 100644
--- a/libnautilus-private/nautilus-directory.c
+++ b/libnautilus-private/nautilus-directory.c
@@ -319,16 +319,6 @@ add_preferences_callbacks (void)
 				  NULL);
 }
 
-static void
-print_key_directory (gpointer key, gpointer value, gpointer callback_data)
-{
-	char *uri;
-
-	uri = g_file_get_uri (G_FILE (key));
-	g_print ("--> %s\n", uri);
-	g_free (uri);
-}
-
 /**
  * nautilus_directory_get_by_uri:
  * @uri: URI of directory to get.
@@ -345,10 +335,7 @@ 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, print_key_directory,
-			 "nautilus-directory.c: directories");
-
+		directories = g_hash_table_new (g_file_hash, (GCompareFunc) g_file_equal);
 		add_preferences_callbacks ();
 	}
 
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index e2b14a7..95e074c 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -549,8 +549,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, NULL, "nautilus-file.c: symbolic_links");
+		symbolic_links = g_hash_table_new (g_str_hash, g_str_equal);
 	}
 
 	target_uri = nautilus_file_get_symbolic_link_target_uri (file);
diff --git a/libnautilus-private/nautilus-signaller.c b/libnautilus-private/nautilus-signaller.c
index dbcdb0a..a26600d 100644
--- a/libnautilus-private/nautilus-signaller.c
+++ b/libnautilus-private/nautilus-signaller.c
@@ -55,7 +55,6 @@ nautilus_signaller_get_current (void)
 
 	if (global_signaller == NULL) {
 		global_signaller = g_object_new (nautilus_signaller_get_type (), NULL);
-		eel_debug_call_at_shutdown_with_data (g_object_unref, global_signaller);
 	}
 
 	return global_signaller;
diff --git a/libnautilus-private/nautilus-thumbnails.c b/libnautilus-private/nautilus-thumbnails.c
index a094701..8a80e51 100644
--- a/libnautilus-private/nautilus-thumbnails.c
+++ b/libnautilus-private/nautilus-thumbnails.c
@@ -473,8 +473,6 @@ get_types_table (void)
 		image_mime_types =
 			g_hash_table_new_full (g_str_hash, g_str_equal,
 					       g_free, NULL);
-		eel_debug_call_at_shutdown_with_data ((GFreeFunc)g_hash_table_destroy,
-						      image_mime_types);
 
 		format_list = gdk_pixbuf_get_formats ();
 		for (l = format_list; l; l = l->next) {
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 547178c..d6d6225 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -5031,13 +5031,11 @@ 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, NULL, "property windows");
+		windows = g_hash_table_new (NULL, NULL);
 	}
 	
 	if (pending_lists == NULL) {
-		pending_lists = eel_g_hash_table_new_free_at_exit
-			(g_str_hash, g_str_equal, NULL, "pending property window files");
+		pending_lists = g_hash_table_new (g_str_hash, g_str_equal);
 	}
 	
 	/* Look to see if there's already a window for this file. */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]