background: Fix a memory leak when monitoring directories

Destroy directory monitors on when the XML object is destroyed.

https://bugzilla.gnome.org/show_bug.cgi?id=709243
This commit is contained in:
Bastien Nocera 2013-10-02 16:32:17 +02:00
parent ca77b20062
commit 5d16f81821

View file

@ -39,6 +39,7 @@ struct CcBackgroundXmlPrivate
GHashTable *wp_hash;
GAsyncQueue *item_added_queue;
guint item_added_id;
GSList *monitors; /* GSList of GFileMonitor */
};
#define CC_BACKGROUND_XML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_BACKGROUND_XML, CcBackgroundXmlPrivate))
@ -371,6 +372,8 @@ cc_background_xml_add_monitor (GFile *directory,
g_signal_connect (monitor, "changed",
G_CALLBACK (gnome_wp_file_changed),
data);
data->priv->monitors = g_slist_prepend (data->priv->monitors, monitor);
}
static void
@ -626,6 +629,8 @@ cc_background_xml_finalize (GObject *object)
g_return_if_fail (xml->priv != NULL);
g_slist_free_full (xml->priv->monitors, g_object_unref);
g_clear_pointer (&xml->priv->wp_hash, g_hash_table_destroy);
if (xml->priv->item_added_id != 0) {
g_source_remove (xml->priv->item_added_id);