diff --git a/glib/gcharset.c b/glib/gcharset.c index cdbc35713..4cf7e67ac 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 781855042..aaa9c0514 100644 --- a/glib/gdataset.c +++ b/glib/gdataset.c @@ -1303,5 +1303,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 1978cf700..0def6ee88 100644 --- a/glib/gdate.c +++ b/glib/gdate.c @@ -47,6 +47,7 @@ #include "gdate.h" +#include "gcleanup.h" #include "gconvert.h" #include "gmem.h" #include "gstrfuncs.h" @@ -889,6 +890,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 (¤t_locale, g_free); +} + /* HOLDS: g_date_global_lock */ static void g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt) @@ -985,7 +999,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 9762dd6b9..dcb84e70c 100644 --- a/glib/gquark.c +++ b/glib/gquark.c @@ -34,6 +34,7 @@ #include +#include "gcleanup.h" #include "gslice.h" #include "ghash.h" #include "gquark.h" @@ -152,6 +153,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 (quark_block, g_free, G_CLEANUP_PHASE_GRAVEYARD); quark_block_offset = 0; } @@ -279,10 +281,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 (quarks_new, g_free, G_CLEANUP_PHASE_GRAVEYARD); g_atomic_pointer_set (&quarks, quarks_new); } if (!quark_ht) @@ -291,6 +290,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 (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 f93c82540..0556edde4 100644 --- a/glib/gtimezone.c +++ b/glib/gtimezone.c @@ -29,6 +29,7 @@ #include #include +#include "gcleanup.h" #include "gmappedfile.h" #include "gtestutils.h" #include "gfileutils.h" @@ -1379,7 +1380,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 7235bedc3..e379dfd4a 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;