[glib/wip/gcleanup: 53/106] gcleanup: Hook up more libglib globals to cleanup



commit e5168ff1edefe4ec89658fe1564237d00fc89cc0
Author: Stef Walter <stefw gnome org>
Date:   Thu Nov 7 22:38:05 2013 +0100

    gcleanup: Hook up more libglib globals to cleanup
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711744

 glib/gcharset.c  |    1 +
 glib/gdataset.c  |    1 +
 glib/gdate.c     |   18 +++++++++++++++++-
 glib/gquark.c    |    7 +++----
 glib/gtimezone.c |    5 ++++-
 glib/gutils.c    |    6 ++----
 6 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/glib/gcharset.c b/glib/gcharset.c
index cdbc357..4cf7e67 100644
--- a/glib/gcharset.c
+++ b/glib/gcharset.c
@@ -51,6 +51,7 @@ get_alias_hash (void)
   if (!alias_hash)
     {
       alias_hash = g_hash_table_new (g_str_hash, g_str_equal);
+      G_CLEANUP (alias_hash, g_hash_table_unref);
 
       aliases = _g_locale_get_charset_aliases ();
       while (*aliases != '\0')
diff --git a/glib/gdataset.c b/glib/gdataset.c
index 006bdc1..b2a8eca 100644
--- a/glib/gdataset.c
+++ b/glib/gdataset.c
@@ -1240,5 +1240,6 @@ g_data_initialize (void)
   g_return_if_fail (g_dataset_location_ht == NULL);
 
   g_dataset_location_ht = g_hash_table_new (g_direct_hash, NULL);
+  G_CLEANUP (g_dataset_location_ht, g_hash_table_unref);
   g_dataset_cached = NULL;
 }
diff --git a/glib/gdate.c b/glib/gdate.c
index 1978cf7..f5cd53d 100644
--- a/glib/gdate.c
+++ b/glib/gdate.c
@@ -889,6 +889,19 @@ typedef struct _GDateParseTokens GDateParseTokens;
 
 #define NUM_LEN 10
 
+static void
+g_date_cleanup (void)
+{
+  int i;
+
+  for (i = 1; i <= 12; i++)
+    {
+      g_clear_pointer (&short_month_names[i], g_free);
+      g_clear_pointer (&long_month_names[i], g_free);
+    }
+  g_clear_pointer (&current_locale, g_free);
+}
+
 /* HOLDS: g_date_global_lock */
 static void
 g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
@@ -985,7 +998,10 @@ g_date_prepare_to_parse (const gchar      *str,
   g_return_if_fail (locale != NULL); /* should not happen */
   
   g_date_clear (&d, 1);              /* clear for scratch use */
-  
+
+  if (current_locale == NULL)
+    G_CLEANUP_FUNC (g_date_cleanup);
+
   if ( (current_locale == NULL) || (strcmp (locale, current_locale) != 0) ) 
     recompute_localeinfo = TRUE;  /* Uh, there used to be a reason for the temporary */
   
diff --git a/glib/gquark.c b/glib/gquark.c
index 9762dd6..b05bcdc 100644
--- a/glib/gquark.c
+++ b/glib/gquark.c
@@ -152,6 +152,7 @@ quark_strdup (const gchar *string)
       QUARK_STRING_BLOCK_SIZE - quark_block_offset < len)
     {
       quark_block = g_malloc (QUARK_STRING_BLOCK_SIZE);
+      G_CLEANUP_IN_PHASE (quark_block, g_free, G_CLEANUP_PHASE_GRAVEYARD);
       quark_block_offset = 0;
     }
 
@@ -279,10 +280,7 @@ quark_new (gchar *string)
       if (quark_seq_id != 0)
         memcpy (quarks_new, quarks, sizeof (char *) * quark_seq_id);
       memset (quarks_new + quark_seq_id, 0, sizeof (char *) * QUARK_BLOCK_SIZE);
-      /* This leaks the old quarks array. Its unfortunate, but it allows
-       * us to do lockless lookup of the arrays, and there shouldn't be that
-       * many quarks in an app
-       */
+      G_CLEANUP_IN_PHASE (quarks_new, g_free, G_CLEANUP_PHASE_GRAVEYARD);
       g_atomic_pointer_set (&quarks, quarks_new);
     }
   if (!quark_ht)
@@ -291,6 +289,7 @@ quark_new (gchar *string)
       quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
       quarks[quark_seq_id] = NULL;
       g_atomic_int_inc (&quark_seq_id);
+      G_CLEANUP_IN_PHASE (quark_ht, g_hash_table_unref, G_CLEANUP_PHASE_GRAVEYARD);
     }
 
   quark = quark_seq_id;
diff --git a/glib/gtimezone.c b/glib/gtimezone.c
index f93c825..671edd8 100644
--- a/glib/gtimezone.c
+++ b/glib/gtimezone.c
@@ -1379,7 +1379,10 @@ g_time_zone_new (const gchar *identifier)
 
   G_LOCK (time_zones);
   if (time_zones == NULL)
-    time_zones = g_hash_table_new (g_str_hash, g_str_equal);
+    {
+      time_zones = g_hash_table_new (g_str_hash, g_str_equal);
+      G_CLEANUP (time_zones, g_hash_table_unref);
+    }
 
   if (identifier)
     {
diff --git a/glib/gutils.c b/glib/gutils.c
index 7235bed..e379dfd 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -1144,10 +1144,6 @@ void
 g_set_prgname (const gchar *prgname)
 {
   G_LOCK (g_prgname);
-  /* We want to use remove here because this is a leak and we want that
-   * to show up in valgrind, so we should _not_ free the original string
-   * during cleanup.
-   */
   if (!g_prgname)
     G_CLEANUP_FUNC (cleanup_prgname);
   g_free (g_prgname);
@@ -2058,6 +2054,7 @@ g_get_system_data_dirs (void)
 #endif
 
       g_system_data_dirs = data_dir_vector;
+      G_CLEANUP (g_system_data_dirs, g_strfreev);
     }
   else
     data_dir_vector = g_system_data_dirs;
@@ -2120,6 +2117,7 @@ g_get_system_config_dirs (void)
 #endif
 
       g_system_config_dirs = conf_dir_vector;
+      G_CLEANUP (g_system_config_dirs, g_strfreev);
     }
   else
     conf_dir_vector = g_system_config_dirs;


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