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; BgFlickrSourcePrivate *priv = BG_FLICKR_SOURCE (object)->priv;
if (priv->client) g_clear_object (&priv->client);
{ g_clear_object (&priv->service);
g_object_unref (priv->client);
priv->client = NULL;
}
if (priv->service)
{
g_object_unref (priv->service);
priv->service = NULL;
}
G_OBJECT_CLASS (bg_flickr_source_parent_class)->dispose (object); 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) if (priv->cancellable)
{ {
g_cancellable_cancel (priv->cancellable); g_cancellable_cancel (priv->cancellable);
g_object_unref (priv->cancellable); g_clear_object (&priv->cancellable);
priv->cancellable = NULL;
} }
if (priv->thumb_factory) g_clear_object (&priv->thumb_factory);
{
g_object_unref (priv->thumb_factory);
priv->thumb_factory = NULL;
}
G_OBJECT_CLASS (bg_pictures_source_parent_class)->dispose (object); 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); BgPicturesSource *bg_source = BG_PICTURES_SOURCE (object);
if (bg_source->priv->thumb_factory) g_clear_object (&bg_source->priv->thumb_factory);
{
g_object_unref (bg_source->priv->thumb_factory);
bg_source->priv->thumb_factory = NULL;
}
if (bg_source->priv->known_items) g_clear_pointer (&bg_source->priv->known_items, g_hash_table_destroy);
{
g_hash_table_destroy (bg_source->priv->known_items);
bg_source->priv->known_items = NULL;
}
g_clear_object (&bg_source->priv->picture_dir_monitor); g_clear_object (&bg_source->priv->picture_dir_monitor);
g_clear_object (&bg_source->priv->cache_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; BgSourcePrivate *priv = BG_SOURCE (object)->priv;
if (priv->store) g_clear_object (&priv->store);
{
g_object_unref (priv->store);
priv->store = NULL;
}
G_OBJECT_CLASS (bg_source_parent_class)->dispose (object); 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; BgWallpapersSourcePrivate *priv = BG_WALLPAPERS_SOURCE (object)->priv;
if (priv->thumb_factory) g_clear_object (&priv->thumb_factory);
{ g_clear_object (&priv->xml);
g_object_unref (priv->thumb_factory);
priv->thumb_factory = NULL;
}
if (priv->xml)
{
g_object_unref (priv->xml);
priv->xml = NULL;
}
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->dispose (object); 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 static void
update_size (CcBackgroundItem *item) update_size (CcBackgroundItem *item)
{ {
g_free (item->priv->size); g_clear_pointer (&item->priv->size, g_free);
item->priv->size = NULL;
if (item->priv->uri == NULL) { if (item->priv->uri == NULL) {
item->priv->size = g_strdup (""); item->priv->size = g_strdup ("");
@ -272,8 +271,7 @@ update_info (CcBackgroundItem *item,
info = g_object_ref (_info); info = g_object_ref (_info);
} }
g_free (item->priv->mime_type); g_clear_pointer (&item->priv->mime_type, g_free);
item->priv->mime_type = NULL;
if (info == NULL if (info == NULL
|| g_file_info_get_content_type (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 */ /* cancel any copy operation */
g_cancellable_cancel (priv->copy_cancellable); g_cancellable_cancel (priv->copy_cancellable);
g_object_unref (priv->copy_cancellable); g_clear_object (&priv->copy_cancellable);
priv->copy_cancellable = NULL;
} }
if (priv->capture_cancellable) if (priv->capture_cancellable)
@ -110,8 +109,7 @@ cc_background_panel_dispose (GObject *object)
/* cancel screenshot operations */ /* cancel screenshot operations */
g_cancellable_cancel (priv->capture_cancellable); g_cancellable_cancel (priv->capture_cancellable);
g_object_unref (priv->capture_cancellable); g_clear_object (&priv->capture_cancellable);
priv->capture_cancellable = NULL;
} }
if (priv->chooser) if (priv->chooser)
@ -123,8 +121,7 @@ cc_background_panel_dispose (GObject *object)
g_clear_object (&priv->thumb_factory); g_clear_object (&priv->thumb_factory);
g_clear_object (&priv->display_screenshot); g_clear_object (&priv->display_screenshot);
g_free (priv->screenshot_path); g_clear_pointer (&priv->screenshot_path, g_free);
priv->screenshot_path = NULL;
g_clear_object (&priv->connection); g_clear_object (&priv->connection);
@ -344,8 +341,7 @@ on_screenshot_finished (GObject *source,
/* remove the temporary file created by the shell */ /* remove the temporary file created by the shell */
g_unlink (panel->priv->screenshot_path); g_unlink (panel->priv->screenshot_path);
g_free (priv->screenshot_path); g_clear_pointer (&priv->screenshot_path, g_free);
priv->screenshot_path = NULL;
cairo_destroy (cr); cairo_destroy (cr);
cairo_surface_destroy (surface); cairo_surface_destroy (surface);
@ -478,8 +474,7 @@ reload_current_bg (CcBackgroundPanel *self,
uri = g_settings_get_string (settings, WP_URI_KEY); uri = g_settings_get_string (settings, WP_URI_KEY);
if (uri && *uri == '\0') if (uri && *uri == '\0')
{ {
g_free (uri); g_clear_pointer (&uri, g_free);
uri = NULL;
} }
else else
{ {

View file

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