gcleanup: Hook up more libglib globals to cleanup

https://bugzilla.gnome.org/show_bug.cgi?id=711744
This commit is contained in:
Stef Walter
2013-11-07 22:38:05 +01:00
parent 75a458a9b4
commit 425d7b7fae
6 changed files with 31 additions and 10 deletions

View File

@@ -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')

View File

@@ -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;
}

View File

@@ -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 (&current_locale, g_free);
}
/* HOLDS: g_date_global_lock */
static void
g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
@@ -986,6 +1000,9 @@ g_date_prepare_to_parse (const gchar *str,
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 */

View File

@@ -34,6 +34,7 @@
#include <string.h>
#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;

View File

@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <signal.h>
#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);
G_CLEANUP (time_zones, g_hash_table_unref);
}
if (identifier)
{

View File

@@ -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;