Skip to content

Commit

Permalink
Add atexit handler for builtin-gconf module
Browse files Browse the repository at this point in the history
Releasing the default_client data makes it easier to detect possible
memory leaks.
  • Loading branch information
spiiroin committed Feb 19, 2014
1 parent a8b4e7e commit 9a484b3
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions builtin-gconf.c
Expand Up @@ -217,17 +217,21 @@ void gconf_value_set_list_type(GConfValue *self, GConfValueType list_type);
GSList *gconf_value_get_list(const GConfValue *self);
void gconf_value_set_list(GConfValue *self, GSList *list);
static GConfEntry *gconf_entry_init(const char *key, const char *type, const char *data);
static void gconf_entry_free(GConfEntry *self);
static void gconf_entry_free_cb(gpointer self);
const char *gconf_entry_get_key(const GConfEntry *entry);
GConfValue *gconf_entry_get_value(const GConfEntry *entry);
#if GCONF_ENABLE_DEBUG_LOGGING
static void gconf_client_debug(GConfClient *self);
#endif
GConfClient *gconf_client_get_default(void);
static void gconf_client_free_default(void);
void gconf_client_add_dir(GConfClient *client, const gchar *dir, GConfClientPreloadType preload, GError **err);
static GConfEntry *gconf_client_find_entry(GConfClient *self, const gchar *key, GError **err);
static GConfValue *gconf_client_find_value(GConfClient *self, const gchar *key, GError **err);
GConfValue *gconf_client_get(GConfClient *self, const gchar *key, GError **err);
static void gconf_client_notify_free(GConfClientNotify *self);
static void gconf_client_notify_free_cb(gpointer self);
static GConfClientNotify *gconf_client_notify_new(const gchar *namespace_section, GConfClientNotifyFunc func, gpointer user_data, GFreeFunc destroy_notify);
static void gconf_client_notify_change(GConfClient *client, const gchar *namespace_section);
guint gconf_client_notify_add(GConfClient *client, const gchar *namespace_section, GConfClientNotifyFunc func, gpointer user_data, GFreeFunc destroy_notify, GError **err);
Expand Down Expand Up @@ -1093,6 +1097,26 @@ gconf_value_set_list(GConfValue *self, GSList *list)
*
* ========================================================================= */

static
void
gconf_entry_free(GConfEntry *self)
{
if( self )
{
gconf_value_free(self->value);
free(self->key);
free(self->def);
free(self);
}
}

static
void
gconf_entry_free_cb(gpointer self)
{
gconf_entry_free(self);
}

/** Create a GConfEntry object */
static
GConfEntry *
Expand Down Expand Up @@ -1671,6 +1695,20 @@ static void gconf_client_mark_defaults(GConfClient *self)
}
}

static void gconf_client_free_default(void)
{
if( default_client )
{
g_slist_free_full(default_client->entries,
gconf_entry_free_cb);

g_slist_free_full(default_client->notify_list,
gconf_client_notify_free_cb);

free(default_client), default_client = 0;
}
}

/** See GConf API documentation */
GConfClient *
gconf_client_get_default(void)
Expand All @@ -1689,6 +1727,7 @@ gconf_client_get_default(void)

// let gconf_client_is_valid() know about this
default_client = self;
atexit(gconf_client_free_default);

// override hard coded defaults via /etc/nn.*.conf
gconf_client_load_overrides(self);
Expand Down Expand Up @@ -1986,6 +2025,13 @@ gconf_client_notify_free(GConfClientNotify *self)
}
}

static
void
gconf_client_notify_free_cb(gpointer self)
{
gconf_client_notify_free(self);
}

/** Create GConfClientNotify object */
static
GConfClientNotify *
Expand Down

0 comments on commit 9a484b3

Please sign in to comment.