background: Use g_clear_* helpers when possible

https://bugzilla.gnome.org/show_bug.cgi?id=707602
This commit is contained in:
Bastien Nocera 2013-09-05 21:55:46 -03:00 committed by Debarshi Ray
parent 531989217e
commit 00d8f80586
7 changed files with 18 additions and 65 deletions

View file

@ -46,17 +46,8 @@ bg_flickr_source_dispose (GObject *object)
{
BgFlickrSourcePrivate *priv = BG_FLICKR_SOURCE (object)->priv;
if (priv->client)
{
g_object_unref (priv->client);
priv->client = NULL;
}
if (priv->service)
{
g_object_unref (priv->service);
priv->service = NULL;
}
g_clear_object (&priv->client);
g_clear_object (&priv->service);
G_OBJECT_CLASS (bg_flickr_source_parent_class)->dispose (object);
}

View file

@ -94,15 +94,10 @@ bg_pictures_source_dispose (GObject *object)
if (priv->cancellable)
{
g_cancellable_cancel (priv->cancellable);
g_object_unref (priv->cancellable);
priv->cancellable = NULL;
g_clear_object (&priv->cancellable);
}
if (priv->thumb_factory)
{
g_object_unref (priv->thumb_factory);
priv->thumb_factory = NULL;
}
g_clear_object (&priv->thumb_factory);
G_OBJECT_CLASS (bg_pictures_source_parent_class)->dispose (object);
}
@ -112,17 +107,9 @@ bg_pictures_source_finalize (GObject *object)
{
BgPicturesSource *bg_source = BG_PICTURES_SOURCE (object);
if (bg_source->priv->thumb_factory)
{
g_object_unref (bg_source->priv->thumb_factory);
bg_source->priv->thumb_factory = NULL;
}
g_clear_object (&bg_source->priv->thumb_factory);
if (bg_source->priv->known_items)
{
g_hash_table_destroy (bg_source->priv->known_items);
bg_source->priv->known_items = NULL;
}
g_clear_pointer (&bg_source->priv->known_items, g_hash_table_destroy);
g_clear_object (&bg_source->priv->picture_dir_monitor);
g_clear_object (&bg_source->priv->cache_dir_monitor);

View file

@ -75,11 +75,7 @@ bg_source_dispose (GObject *object)
{
BgSourcePrivate *priv = BG_SOURCE (object)->priv;
if (priv->store)
{
g_object_unref (priv->store);
priv->store = NULL;
}
g_clear_object (&priv->store);
G_OBJECT_CLASS (bg_source_parent_class)->dispose (object);
}

View file

@ -72,16 +72,8 @@ bg_wallpapers_source_dispose (GObject *object)
{
BgWallpapersSourcePrivate *priv = BG_WALLPAPERS_SOURCE (object)->priv;
if (priv->thumb_factory)
{
g_object_unref (priv->thumb_factory);
priv->thumb_factory = NULL;
}
if (priv->xml)
{
g_object_unref (priv->xml);
priv->xml = NULL;
}
g_clear_object (&priv->thumb_factory);
g_clear_object (&priv->xml);
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->dispose (object);
}

View file

@ -140,8 +140,7 @@ cc_background_item_changes_with_time (CcBackgroundItem *item)
static void
update_size (CcBackgroundItem *item)
{
g_free (item->priv->size);
item->priv->size = NULL;
g_clear_pointer (&item->priv->size, g_free);
if (item->priv->uri == NULL) {
item->priv->size = g_strdup ("");
@ -272,8 +271,7 @@ update_info (CcBackgroundItem *item,
info = g_object_ref (_info);
}
g_free (item->priv->mime_type);
item->priv->mime_type = NULL;
g_clear_pointer (&item->priv->mime_type, g_free);
if (info == NULL
|| g_file_info_get_content_type (info) == NULL) {

View file

@ -101,8 +101,7 @@ cc_background_panel_dispose (GObject *object)
/* cancel any copy operation */
g_cancellable_cancel (priv->copy_cancellable);
g_object_unref (priv->copy_cancellable);
priv->copy_cancellable = NULL;
g_clear_object (&priv->copy_cancellable);
}
if (priv->capture_cancellable)
@ -110,8 +109,7 @@ cc_background_panel_dispose (GObject *object)
/* cancel screenshot operations */
g_cancellable_cancel (priv->capture_cancellable);
g_object_unref (priv->capture_cancellable);
priv->capture_cancellable = NULL;
g_clear_object (&priv->capture_cancellable);
}
if (priv->chooser)
@ -123,8 +121,7 @@ cc_background_panel_dispose (GObject *object)
g_clear_object (&priv->thumb_factory);
g_clear_object (&priv->display_screenshot);
g_free (priv->screenshot_path);
priv->screenshot_path = NULL;
g_clear_pointer (&priv->screenshot_path, g_free);
g_clear_object (&priv->connection);
@ -344,8 +341,7 @@ on_screenshot_finished (GObject *source,
/* remove the temporary file created by the shell */
g_unlink (panel->priv->screenshot_path);
g_free (priv->screenshot_path);
priv->screenshot_path = NULL;
g_clear_pointer (&priv->screenshot_path, g_free);
cairo_destroy (cr);
cairo_surface_destroy (surface);
@ -478,8 +474,7 @@ reload_current_bg (CcBackgroundPanel *self,
uri = g_settings_get_string (settings, WP_URI_KEY);
if (uri && *uri == '\0')
{
g_free (uri);
uri = NULL;
g_clear_pointer (&uri, g_free);
}
else
{

View file

@ -623,18 +623,12 @@ cc_background_xml_finalize (GObject *object)
g_return_if_fail (xml->priv != NULL);
if (xml->priv->wp_hash) {
g_hash_table_destroy (xml->priv->wp_hash);
xml->priv->wp_hash = NULL;
}
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);
xml->priv->item_added_id = 0;
}
if (xml->priv->item_added_queue) {
g_async_queue_unref (xml->priv->item_added_queue);
xml->priv->item_added_queue = NULL;
}
g_clear_pointer (&xml->priv->item_added_queue, g_async_queue_unref);
}
static void