diff options
30 files changed, 133 insertions, 360 deletions
diff --git a/applets/clock/calendar-window.c b/applets/clock/calendar-window.c index 8fe2c77c..11003d28 100644 --- a/applets/clock/calendar-window.c +++ b/applets/clock/calendar-window.c @@ -617,17 +617,15 @@ calendar_window_set_prefs_path (CalendarWindow *calwin, !strcmp (calwin->priv->prefs_path, prefs_path)) return; - if (calwin->priv->prefs_path) - g_free (calwin->priv->prefs_path); - calwin->priv->prefs_path = NULL; - + g_free (calwin->priv->prefs_path); if (prefs_path && prefs_path [0]) calwin->priv->prefs_path = g_strdup (prefs_path); + else + calwin->priv->prefs_path = NULL; g_object_notify (G_OBJECT (calwin), "prefs-path"); if (calwin->priv->settings) g_object_unref (calwin->priv->settings); - calwin->priv->settings = g_settings_new_with_path (CLOCK_SCHEMA, calwin->priv->prefs_path); } diff --git a/applets/clock/clock-face.c b/applets/clock/clock-face.c index a30afd13..7340c8a8 100644 --- a/applets/clock/clock-face.c +++ b/applets/clock/clock-face.c @@ -369,20 +369,9 @@ clock_face_finalize (GObject *obj) { ClockFacePrivate *priv = clock_face_get_instance_private (CLOCK_FACE(obj)); - if (priv->location) { - g_object_unref (priv->location); - priv->location = NULL; - } - - if (priv->face_pixbuf) { - g_object_unref (priv->face_pixbuf); - priv->face_pixbuf = NULL; - } - - if (priv->size_widget) { - g_object_unref (priv->size_widget); - priv->size_widget = NULL; - } + g_clear_object (&priv->location); + g_clear_object (&priv->face_pixbuf); + g_clear_object (&priv->size_widget); G_OBJECT_CLASS (clock_face_parent_class)->finalize (obj); diff --git a/applets/clock/clock-location-tile.c b/applets/clock/clock-location-tile.c index 55bc749a..b70f467c 100644 --- a/applets/clock/clock-location-tile.c +++ b/applets/clock/clock-location-tile.c @@ -143,19 +143,11 @@ clock_location_tile_finalize (GObject *g_obj) g_signal_handler_disconnect (priv->location, priv->location_weather_updated_id); priv->location_weather_updated_id = 0; - g_object_unref (priv->location); - priv->location = NULL; + g_clear_object (&priv->location); } - if (priv->button_group) { - g_object_unref (priv->button_group); - priv->button_group = NULL; - } - - if (priv->current_group) { - g_object_unref (priv->current_group); - priv->current_group = NULL; - } + g_clear_object (&priv->button_group); + g_clear_object (&priv->current_group); G_OBJECT_CLASS (clock_location_tile_parent_class)->finalize (g_obj); } diff --git a/applets/clock/clock-location.c b/applets/clock/clock-location.c index 67af64b1..637d834d 100644 --- a/applets/clock/clock-location.c +++ b/applets/clock/clock-location.c @@ -210,17 +210,14 @@ clock_location_finalize (GObject *g_obj) G_CALLBACK (network_changed), CLOCK_LOCATION (g_obj)); - g_free (priv->name); - g_free (priv->city); + g_clear_pointer (&priv->name, g_free); + g_clear_pointer (&priv->city, g_free); - if (priv->systz) { - g_object_unref (priv->systz); - priv->systz = NULL; - } + g_clear_object (&priv->systz); - g_free (priv->timezone); - g_free (priv->tzname); - g_free (priv->weather_code); + g_clear_pointer (&priv->timezone, g_free); + g_clear_pointer (&priv->tzname, g_free); + g_clear_pointer (&priv->weather_code, g_free); if (priv->weather_info) { weather_info_free (priv->weather_info); diff --git a/applets/clock/clock-map.c b/applets/clock/clock-map.c index fc096c60..97441c62 100644 --- a/applets/clock/clock-map.c +++ b/applets/clock/clock-map.c @@ -150,32 +150,15 @@ clock_map_finalize (GObject *g_obj) priv->highlight_timeout_id = 0; } - if (priv->stock_map_pixbuf) { - g_object_unref (priv->stock_map_pixbuf); - priv->stock_map_pixbuf = NULL; - } + g_clear_object (&priv->stock_map_pixbuf); for (i = 0; i < MARKER_NB; i++) { - if (priv->location_marker_pixbuf[i]) { - g_object_unref (priv->location_marker_pixbuf[i]); - priv->location_marker_pixbuf[i] = NULL; - } + g_clear_object (&priv->location_marker_pixbuf[i]); } - if (priv->location_map_pixbuf) { - g_object_unref (priv->location_map_pixbuf); - priv->location_map_pixbuf = NULL; - } - - if (priv->shadow_pixbuf) { - g_object_unref (priv->shadow_pixbuf); - priv->shadow_pixbuf = NULL; - } - - if (priv->shadow_map_pixbuf) { - g_object_unref (priv->shadow_map_pixbuf); - priv->shadow_map_pixbuf = NULL; - } + g_clear_object (&priv->location_map_pixbuf); + g_clear_object (&priv->shadow_pixbuf); + g_clear_object (&priv->shadow_map_pixbuf); G_OBJECT_CLASS (clock_map_parent_class)->finalize (g_obj); } diff --git a/applets/clock/system-timezone.c b/applets/clock/system-timezone.c index 801f3386..b7b3d64b 100644 --- a/applets/clock/system-timezone.c +++ b/applets/clock/system-timezone.c @@ -234,13 +234,11 @@ system_timezone_finalize (GObject *obj) systz = SYSTEM_TIMEZONE (obj); priv = system_timezone_get_instance_private (systz); - g_free (priv->tz); - g_free (priv->env_tz); + g_clear_pointer (&priv->tz, g_free); + g_clear_pointer (&priv->env_tz, g_free); for (i = 0; i < CHECK_NB; i++) { - if (priv->monitors[i]) - g_object_unref (priv->monitors[i]); - priv->monitors[i] = NULL; + g_clear_object (&priv->monitors[i]); } G_OBJECT_CLASS (system_timezone_parent_class)->finalize (obj); diff --git a/applets/fish/fish.c b/applets/fish/fish.c index 2cded044..cfbdf3fa 100644 --- a/applets/fish/fish.c +++ b/applets/fish/fish.c @@ -1778,28 +1778,14 @@ static void fish_applet_dispose (GObject *object) fish); if (fish->timeout) - { g_source_remove (fish->timeout); - } - fish->timeout = 0; - if (fish->settings) - g_object_unref (fish->settings); - fish->settings = NULL; - - if (fish->lockdown_settings) - g_object_unref (fish->lockdown_settings); - fish->lockdown_settings = NULL; - - g_free (fish->name); - fish->name = NULL; - - g_free (fish->image); - fish->image = NULL; - - g_free (fish->command); - fish->command = NULL; + g_clear_object (&fish->settings); + g_clear_object (&fish->lockdown_settings); + g_clear_pointer (&fish->name, g_free); + g_clear_pointer (&fish->image, g_free); + g_clear_pointer (&fish->command, g_free); if (fish->surface) cairo_surface_destroy (fish->surface); @@ -1807,9 +1793,7 @@ static void fish_applet_dispose (GObject *object) fish->surface_width = 0; fish->surface_height = 0; - if (fish->pixbuf) - g_object_unref (fish->pixbuf); - fish->pixbuf = NULL; + g_clear_object (&fish->pixbuf); if (fish->preferences_dialog) gtk_widget_destroy (fish->preferences_dialog); diff --git a/applets/notification_area/status-notifier/sn-dbus-menu.c b/applets/notification_area/status-notifier/sn-dbus-menu.c index 03a95a4b..323663a5 100644 --- a/applets/notification_area/status-notifier/sn-dbus-menu.c +++ b/applets/notification_area/status-notifier/sn-dbus-menu.c @@ -419,8 +419,8 @@ sn_dbus_menu_finalize (GObject *object) menu = SN_DBUS_MENU (object); - g_free (menu->bus_name); - g_free (menu->object_path); + g_clear_pointer (&menu->bus_name, g_free); + g_clear_pointer (&menu->object_path, g_free); G_OBJECT_CLASS (sn_dbus_menu_parent_class)->finalize (object); } diff --git a/applets/notification_area/status-notifier/sn-item-v0.c b/applets/notification_area/status-notifier/sn-item-v0.c index 3ec4d037..d302cbf9 100644 --- a/applets/notification_area/status-notifier/sn-item-v0.c +++ b/applets/notification_area/status-notifier/sn-item-v0.c @@ -640,7 +640,7 @@ update_title (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->title, g_free); + g_free (v0->title); v0->title = g_variant_dup_string (variant, NULL); g_clear_pointer (&variant, g_variant_unref); @@ -668,7 +668,7 @@ update_icon_name (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->icon_name, g_free); + g_free (v0->icon_name); v0->icon_name = g_variant_dup_string (variant, NULL); g_clear_pointer (&variant, g_variant_unref); @@ -719,7 +719,7 @@ update_overlay_icon_name (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->overlay_icon_name, g_free); + g_free (v0->overlay_icon_name); v0->overlay_icon_name = g_variant_dup_string (variant, NULL); g_clear_pointer (&variant, g_variant_unref); @@ -770,7 +770,7 @@ update_attention_icon_name (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->attention_icon_name, g_free); + g_free (v0->attention_icon_name); v0->attention_icon_name = g_variant_dup_string (variant, NULL); g_clear_pointer (&variant, g_variant_unref); @@ -792,7 +792,7 @@ update_attention_icon_pixmap (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->attention_icon_pixmap, icon_pixmap_free); + icon_pixmap_free (v0->attention_icon_pixmap); v0->attention_icon_pixmap = icon_pixmap_new (variant); g_clear_pointer (&variant, g_variant_unref); @@ -821,7 +821,7 @@ update_tooltip (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->tooltip, sn_tooltip_free); + sn_tooltip_free (v0->tooltip); v0->tooltip = sn_tooltip_new (variant); g_clear_pointer (&variant, g_variant_unref); diff --git a/applets/notification_area/system-tray/na-tray.c b/applets/notification_area/system-tray/na-tray.c index fee75dc8..df5c6791 100644 --- a/applets/notification_area/system-tray/na-tray.c +++ b/applets/notification_area/system-tray/na-tray.c @@ -161,13 +161,9 @@ static void icon_tip_buffer_free (gpointer data, gpointer userdata) { - IconTipBuffer *buffer; - - buffer = data; + IconTipBuffer *buffer = data; g_free (buffer->text); - buffer->text = NULL; - g_free (buffer); } diff --git a/libmate-panel-applet/mate-panel-applet-factory.c b/libmate-panel-applet/mate-panel-applet-factory.c index c0465eb8..521ab4d4 100644 --- a/libmate-panel-applet/mate-panel-applet-factory.c +++ b/libmate-panel-applet/mate-panel-applet-factory.c @@ -78,10 +78,7 @@ mate_panel_applet_factory_finalize (GObject *object) factories = NULL; } - if (factory->factory_id) { - g_free (factory->factory_id); - factory->factory_id = NULL; - } + g_clear_pointer (&factory->factory_id, g_free); if (factory->applets) { g_hash_table_unref (factory->applets); diff --git a/libmate-panel-applet/mate-panel-applet.c b/libmate-panel-applet/mate-panel-applet.c index fc42554a..1a1751c6 100644 --- a/libmate-panel-applet/mate-panel-applet.c +++ b/libmate-panel-applet/mate-panel-applet.c @@ -845,36 +845,21 @@ mate_panel_applet_finalize (GObject *object) g_dbus_connection_unregister_object (priv->connection, priv->object_id); priv->object_id = 0; - g_object_unref (priv->connection); - priv->connection = NULL; + g_clear_object (&priv->connection); } - if (priv->object_path) { - g_free (priv->object_path); - priv->object_path = NULL; - } + g_clear_pointer (&priv->object_path, g_free); mate_panel_applet_set_preferences_path (applet, NULL); - if (priv->applet_action_group) { - g_object_unref (priv->applet_action_group); - priv->applet_action_group = NULL; - } - - if (priv->panel_action_group) { - g_object_unref (priv->panel_action_group); - priv->panel_action_group = NULL; - } + g_clear_object (&priv->applet_action_group); + g_clear_object (&priv->panel_action_group); + g_clear_object (&priv->ui_manager); - if (priv->ui_manager) { - g_object_unref (priv->ui_manager); - priv->ui_manager = NULL; - } - - g_free (priv->size_hints); - g_free (priv->prefs_path); - g_free (priv->background); - g_free (priv->id); + g_clear_pointer (&priv->size_hints, g_free); + g_clear_pointer (&priv->prefs_path, g_free); + g_clear_pointer (&priv->background, g_free); + g_clear_pointer (&priv->id, g_free); /* closure is owned by the factory */ priv->closure = NULL; diff --git a/mate-panel/applet.c b/mate-panel/applet.c index 3f25ead1..160861e7 100644 --- a/mate-panel/applet.c +++ b/mate-panel/applet.c @@ -762,8 +762,6 @@ mate_panel_applet_destroy (GtkWidget *widget, mate_panel_applet_clear_user_menu (info); g_free (info->id); - info->id = NULL; - g_free (info); } @@ -791,11 +789,7 @@ static void free_applet_to_load (MatePanelAppletToLoad *applet) { g_free (applet->id); - applet->id = NULL; - g_free (applet->toplevel_id); - applet->toplevel_id = NULL; - g_free (applet); } diff --git a/mate-panel/button-widget.c b/mate-panel/button-widget.c index 6b839bc6..cd38a97f 100644 --- a/mate-panel/button-widget.c +++ b/mate-panel/button-widget.c @@ -209,8 +209,7 @@ button_widget_finalize (GObject *object) button_widget_unset_surfaces (button); - g_free (button->priv->filename); - button->priv->filename = NULL; + g_clear_pointer (&button->priv->filename, g_free); G_OBJECT_CLASS (button_widget_parent_class)->finalize (object); } diff --git a/mate-panel/launcher.c b/mate-panel/launcher.c index 5ef95b21..0a536c96 100644 --- a/mate-panel/launcher.c +++ b/mate-panel/launcher.c @@ -251,14 +251,12 @@ free_launcher (gpointer data) if (launcher->key_file) g_key_file_free (launcher->key_file); - launcher->key_file = NULL; - if (launcher->location != NULL) - g_free (launcher->location); - launcher->location = NULL; + g_free (launcher->location); if (launcher->monitor != NULL) g_object_unref (launcher->monitor); + g_free (launcher); } @@ -640,10 +638,8 @@ setup_button (Launcher *launcher) /* Setup icon */ icon = panel_key_file_get_locale_string (launcher->key_file, "Icon"); - if (icon && icon[0] == '\0') { - g_free (icon); - icon = NULL; - } + if (icon && icon[0] == '\0') + g_clear_pointer (&icon, g_free); if (!icon) { gchar *exec; diff --git a/mate-panel/libmate-panel-applet-private/panel-applet-container.c b/mate-panel/libmate-panel-applet-private/panel-applet-container.c index 2ce58402..c31c058d 100644 --- a/mate-panel/libmate-panel-applet-private/panel-applet-container.c +++ b/mate-panel/libmate-panel-applet-private/panel-applet-container.c @@ -161,25 +161,15 @@ mate_panel_applet_container_dispose (GObject *object) container->priv->pending_ops = NULL; } - if (container->priv->bus_name) { - g_free (container->priv->bus_name); - container->priv->bus_name = NULL; - } - - if (container->priv->iid) { - g_free (container->priv->iid); - container->priv->iid = NULL; - } + g_clear_pointer (&container->priv->bus_name, g_free); + g_clear_pointer (&container->priv->iid, g_free); if (container->priv->name_watcher_id > 0) { g_bus_unwatch_name (container->priv->name_watcher_id); container->priv->name_watcher_id = 0; } - if (container->priv->applet_proxy) { - g_object_unref (container->priv->applet_proxy); - container->priv->applet_proxy = NULL; - } + g_clear_object (&container->priv->applet_proxy); G_OBJECT_CLASS (mate_panel_applet_container_parent_class)->dispose (object); } @@ -765,7 +755,7 @@ mate_panel_applet_container_child_get_finish (MatePanelAppletContainer *containe { g_return_val_if_fail (g_task_is_valid (result, container), NULL); g_warn_if_fail (g_task_get_source_tag (G_TASK (result)) == mate_panel_applet_container_child_get); - + return g_variant_ref (g_task_propagate_pointer (G_TASK (result), error)); } diff --git a/mate-panel/libpanel-util/panel-icon-chooser.c b/mate-panel/libpanel-util/panel-icon-chooser.c index 1e6c0ca3..c99503bd 100644 --- a/mate-panel/libpanel-util/panel-icon-chooser.c +++ b/mate-panel/libpanel-util/panel-icon-chooser.c @@ -153,17 +153,9 @@ panel_icon_chooser_dispose (GObject *object) /* remember, destroy can be run multiple times! */ - if (chooser->priv->fallback_icon_name != NULL) - g_free (chooser->priv->fallback_icon_name); - chooser->priv->fallback_icon_name = NULL; - - if (chooser->priv->icon != NULL) - g_free (chooser->priv->icon); - chooser->priv->icon = NULL; - - if (chooser->priv->icon_theme_dir != NULL) - g_free (chooser->priv->icon_theme_dir); - chooser->priv->icon_theme_dir = NULL; + g_clear_pointer (&chooser->priv->fallback_icon_name, g_free); + g_clear_pointer (&chooser->priv->icon, g_free); + g_clear_pointer (&chooser->priv->icon_theme_dir, g_free); G_OBJECT_CLASS (panel_icon_chooser_parent_class)->dispose (object); } @@ -504,8 +496,7 @@ panel_icon_chooser_set_fallback_icon_name (PanelIconChooser *chooser, if (g_strcmp0 (chooser->priv->fallback_icon_name, fallback_icon_name) == 0) return; - if (chooser->priv->fallback_icon_name) - g_free (chooser->priv->fallback_icon_name); + g_free (chooser->priv->fallback_icon_name); chooser->priv->fallback_icon_name = g_strdup (fallback_icon_name); _panel_icon_chooser_update (chooser); @@ -530,8 +521,7 @@ panel_icon_chooser_set_icon (PanelIconChooser *chooser, if (g_strcmp0 (chooser->priv->icon, icon) == 0) return; - if (chooser->priv->icon) - g_free (chooser->priv->icon); + g_free (chooser->priv->icon); chooser->priv->icon = g_strdup (icon); _panel_icon_chooser_update (chooser); diff --git a/mate-panel/libpanel-util/panel-keyfile.c b/mate-panel/libpanel-util/panel-keyfile.c index 2b58dc3a..0b0104ef 100644 --- a/mate-panel/libpanel-util/panel-keyfile.c +++ b/mate-panel/libpanel-util/panel-keyfile.c @@ -293,8 +293,7 @@ panel_key_file_remove_locale_key (GKeyFile *keyfile, locale_key, NULL)) break; - g_free (locale_key); - locale_key = NULL; + g_clear_pointer (&locale_key, g_free); } } diff --git a/mate-panel/libpanel-util/panel-session-manager.c b/mate-panel/libpanel-util/panel-session-manager.c index afd09501..a4a17862 100644 --- a/mate-panel/libpanel-util/panel-session-manager.c +++ b/mate-panel/libpanel-util/panel-session-manager.c @@ -39,8 +39,7 @@ panel_session_manager_finalize (GObject *object) { PanelSessionManager *manager = PANEL_SESSION_MANAGER (object); - if (manager->proxy != NULL) - g_object_unref (manager->proxy); + g_clear_object (&manager->proxy); G_OBJECT_CLASS (panel_session_manager_parent_class)->finalize (object); } diff --git a/mate-panel/panel-action-button.c b/mate-panel/panel-action-button.c index 8a040651..12c7b2fa 100644 --- a/mate-panel/panel-action-button.c +++ b/mate-panel/panel-action-button.c @@ -477,8 +477,7 @@ panel_action_button_finalize (GObject *object) g_signal_handlers_disconnect_by_func (button->priv->settings, G_CALLBACK (panel_action_button_type_changed), button); - g_object_unref (button->priv->settings); - button->priv->settings = NULL; + g_clear_object (&button->priv->settings); } button->priv->info = NULL; diff --git a/mate-panel/panel-addto.c b/mate-panel/panel-addto.c index b85d6ce8..8b559b75 100644 --- a/mate-panel/panel-addto.c +++ b/mate-panel/panel-addto.c @@ -893,9 +893,7 @@ panel_addto_present_applications (PanelAddtoDialog *dialog) dialog->search_entry); gtk_widget_set_sensitive (dialog->back_button, TRUE); - if (dialog->applet_search_text) - g_free (dialog->applet_search_text); - + g_free (dialog->applet_search_text); dialog->applet_search_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->search_entry))); /* show everything */ gtk_entry_set_text (GTK_ENTRY (dialog->search_entry), ""); @@ -915,11 +913,8 @@ panel_addto_present_applets (PanelAddtoDialog *dialog) if (dialog->applet_search_text) { gtk_entry_set_text (GTK_ENTRY (dialog->search_entry), dialog->applet_search_text); - gtk_editable_set_position (GTK_EDITABLE (dialog->search_entry), - -1); - - g_free (dialog->applet_search_text); - dialog->applet_search_text = NULL; + gtk_editable_set_position (GTK_EDITABLE (dialog->search_entry), -1); + g_clear_pointer (&dialog->applet_search_text, g_free); } } @@ -929,33 +924,13 @@ panel_addto_dialog_free_item_info (PanelAddtoItemInfo *item_info) if (item_info == NULL || item_info->static_data) return; - if (item_info->name != NULL) - g_free (item_info->name); - item_info->name = NULL; - - if (item_info->description != NULL) - g_free (item_info->description); - item_info->description = NULL; - - if (item_info->icon != NULL) - g_free (item_info->icon); - item_info->icon = NULL; - - if (item_info->iid != NULL) - g_free (item_info->iid); - item_info->iid = NULL; - - if (item_info->launcher_path != NULL) - g_free (item_info->launcher_path); - item_info->launcher_path = NULL; - - if (item_info->menu_filename != NULL) - g_free (item_info->menu_filename); - item_info->menu_filename = NULL; - - if (item_info->menu_path != NULL) - g_free (item_info->menu_path); - item_info->menu_path = NULL; + g_clear_pointer (&item_info->name, g_free); + g_clear_pointer (&item_info->description, g_free); + g_clear_pointer (&item_info->icon, g_free); + g_clear_pointer (&item_info->iid, g_free); + g_clear_pointer (&item_info->launcher_path, g_free); + g_clear_pointer (&item_info->menu_filename, g_free); + g_clear_pointer (&item_info->menu_path, g_free); } static void @@ -992,13 +967,8 @@ panel_addto_dialog_free (PanelAddtoDialog *dialog) G_CALLBACK (panel_addto_name_notify), dialog); - if (dialog->search_text) - g_free (dialog->search_text); - dialog->search_text = NULL; - - if (dialog->applet_search_text) - g_free (dialog->applet_search_text); - dialog->applet_search_text = NULL; + g_free (dialog->search_text); + g_free (dialog->applet_search_text); if (dialog->addto_dialog) gtk_widget_destroy (dialog->addto_dialog); @@ -1018,22 +988,10 @@ panel_addto_dialog_free (PanelAddtoDialog *dialog) panel_addto_dialog_free_application_list (dialog->application_list); panel_addto_dialog_free_application_list (dialog->settings_list); - if (dialog->filter_applet_model) - g_object_unref (dialog->filter_applet_model); - dialog->filter_applet_model = NULL; - - if (dialog->applet_model) - g_object_unref (dialog->applet_model); - dialog->applet_model = NULL; - - if (dialog->filter_application_model) - g_object_unref (dialog->filter_application_model); - dialog->filter_application_model = NULL; - - if (dialog->application_model) - g_object_unref (dialog->application_model); - dialog->application_model = NULL; - + g_clear_object (&dialog->filter_applet_model); + g_clear_object (&dialog->applet_model); + g_clear_object (&dialog->filter_application_model); + g_clear_object (&dialog->application_model); g_clear_object (&dialog->menu_tree); g_free (dialog); @@ -1127,8 +1085,7 @@ panel_addto_search_entry_changed (GtkWidget *entry, return; } - if (dialog->search_text) - g_free (dialog->search_text); + g_free (dialog->search_text); dialog->search_text = new_text; model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->tree_view)); diff --git a/mate-panel/panel-applet-frame.c b/mate-panel/panel-applet-frame.c index ed85d3e5..80d9b311 100644 --- a/mate-panel/panel-applet-frame.c +++ b/mate-panel/panel-applet-frame.c @@ -438,8 +438,7 @@ mate_panel_applet_frame_finalize (GObject *object) panel_lockdown_notify_remove (G_CALLBACK (mate_panel_applet_frame_sync_menu_state), frame); - g_free (frame->priv->iid); - frame->priv->iid = NULL; + g_clear_pointer (&frame->priv->iid, g_free); G_OBJECT_CLASS (mate_panel_applet_frame_parent_class)->finalize (object); } @@ -552,8 +551,7 @@ void _mate_panel_applet_frame_set_iid (MatePanelAppletFrame *frame, const gchar *iid) { - if (frame->priv->iid) - g_free (frame->priv->iid); + g_free (frame->priv->iid); frame->priv->iid = g_strdup (iid); } diff --git a/mate-panel/panel-background.c b/mate-panel/panel-background.c index 4ac5d589..0fae438e 100644 --- a/mate-panel/panel-background.c +++ b/mate-panel/panel-background.c @@ -490,16 +490,13 @@ static void panel_background_set_image_no_update (PanelBackground *background, const char *image) { - if (background->loaded_image) - g_object_unref (background->loaded_image); - background->loaded_image = NULL; - - if (background->image) - g_free (background->image); - background->image = NULL; + g_clear_object (&background->loaded_image); + g_free (background->image); if (image && image [0]) background->image = g_strdup (image); + else + background->image = NULL; panel_background_update_has_alpha (background); } @@ -756,17 +753,10 @@ panel_background_free (PanelBackground *background) { free_transformed_resources (background); - if (background->image) - g_free (background->image); - background->image = NULL; - - if (background->loaded_image) - g_object_unref (background->loaded_image); - background->loaded_image = NULL; + g_clear_pointer (&background->image, g_free); - if (background->window) - g_object_unref (background->window); - background->window = NULL; + g_clear_object (&background->loaded_image); + g_clear_object (&background->window); if (background->default_pattern) cairo_pattern_destroy (background->default_pattern); diff --git a/mate-panel/panel-ditem-editor.c b/mate-panel/panel-ditem-editor.c index ebcc91a6..2762ccc1 100644 --- a/mate-panel/panel-ditem-editor.c +++ b/mate-panel/panel-ditem-editor.c @@ -372,8 +372,7 @@ panel_ditem_editor_dispose (GObject *object) g_key_file_free (dialog->priv->revert_key_file); dialog->priv->revert_key_file = NULL; - g_free (dialog->priv->uri); - dialog->priv->uri = NULL; + g_clear_pointer (&dialog->priv->uri, g_free); G_OBJECT_CLASS (panel_ditem_editor_parent_class)->dispose (object); } diff --git a/mate-panel/panel-menu-button.c b/mate-panel/panel-menu-button.c index 2a35b76d..fda621c0 100644 --- a/mate-panel/panel-menu-button.c +++ b/mate-panel/panel-menu-button.c @@ -215,17 +215,10 @@ panel_menu_button_finalize (GObject *object) button->priv->menu = NULL; } - g_free (button->priv->applet_id); - button->priv->applet_id = NULL; - - g_free (button->priv->menu_path); - button->priv->menu_path = NULL; - - g_free (button->priv->custom_icon); - button->priv->custom_icon = NULL; - - g_free (button->priv->tooltip); - button->priv->tooltip = NULL; + g_clear_pointer (&button->priv->applet_id, g_free); + g_clear_pointer (&button->priv->menu_path, g_free); + g_clear_pointer (&button->priv->custom_icon, g_free); + g_clear_pointer (&button->priv->tooltip, g_free); G_OBJECT_CLASS (panel_menu_button_parent_class)->finalize (object); } @@ -824,8 +817,6 @@ panel_menu_button_set_menu_path (PanelMenuButton *button, return; g_free (button->priv->menu_path); - button->priv->menu_path = NULL; - button->priv->menu_path = g_strdup (menu_path); if (button->priv->menu) @@ -842,10 +833,10 @@ panel_menu_button_set_custom_icon (PanelMenuButton *button, g_return_if_fail (PANEL_IS_MENU_BUTTON (button)); g_free (button->priv->custom_icon); - button->priv->custom_icon = NULL; - if (custom_icon && custom_icon [0]) button->priv->custom_icon = g_strdup (custom_icon); + else + button->priv->custom_icon = NULL; panel_menu_button_set_icon (button); } @@ -857,11 +848,11 @@ panel_menu_button_set_tooltip (PanelMenuButton *button, g_return_if_fail (PANEL_IS_MENU_BUTTON (button)); g_free (button->priv->tooltip); - button->priv->tooltip = NULL; - if (tooltip && tooltip [0]) { button->priv->tooltip = g_strdup (tooltip); panel_util_set_tooltip_text (GTK_WIDGET (button), tooltip); + } else { + button->priv->tooltip = NULL; } } @@ -878,9 +869,10 @@ panel_menu_button_set_use_menu_path (PanelMenuButton *button, button->priv->use_menu_path = use_menu_path; - if (button->priv->menu) + if (button->priv->menu) { gtk_menu_detach (GTK_MENU (button->priv->menu)); - button->priv->menu = NULL; + button->priv->menu = NULL; + } panel_menu_button_set_icon (button); } diff --git a/mate-panel/panel-menu-items.c b/mate-panel/panel-menu-items.c index 1cdc9284..785acee4 100644 --- a/mate-panel/panel-menu-items.c +++ b/mate-panel/panel-menu-items.c @@ -1265,23 +1265,14 @@ panel_place_menu_item_finalize (GObject *object) { PanelPlaceMenuItem *menuitem = (PanelPlaceMenuItem *) object; - if (menuitem->priv->caja_desktop_settings) { - g_object_unref (menuitem->priv->caja_desktop_settings); - menuitem->priv->caja_desktop_settings = NULL; - } - if (menuitem->priv->caja_prefs_settings) { - g_object_unref (menuitem->priv->caja_prefs_settings); - menuitem->priv->caja_prefs_settings = NULL; - } - - g_object_unref (menuitem->priv->menubar_settings); - menuitem->priv->menubar_settings = NULL; + g_clear_object (&menuitem->priv->caja_desktop_settings); + g_clear_object (&menuitem->priv->caja_prefs_settings); + g_clear_object (&menuitem->priv->menubar_settings); if (menuitem->priv->bookmarks_monitor != NULL) { g_file_monitor_cancel (menuitem->priv->bookmarks_monitor); - g_object_unref (menuitem->priv->bookmarks_monitor); + g_clear_object (&menuitem->priv->bookmarks_monitor); } - menuitem->priv->bookmarks_monitor = NULL; if (menuitem->priv->drive_changed_id) g_signal_handler_disconnect (menuitem->priv->volume_monitor, @@ -1328,9 +1319,7 @@ panel_place_menu_item_finalize (GObject *object) menuitem->priv->mount_removed_id); menuitem->priv->mount_removed_id = 0; - if (menuitem->priv->volume_monitor != NULL) - g_object_unref (menuitem->priv->volume_monitor); - menuitem->priv->volume_monitor = NULL; + g_clear_object (&menuitem->priv->volume_monitor); G_OBJECT_CLASS (panel_place_menu_item_parent_class)->finalize (object); } diff --git a/mate-panel/panel-profile.c b/mate-panel/panel-profile.c index bd6d3a07..cd114261 100644 --- a/mate-panel/panel-profile.c +++ b/mate-panel/panel-profile.c @@ -158,8 +158,7 @@ panel_profile_find_new_id (PanelGSettingsKeyType type) for (j = 0; existing_ids[j] != NULL; j++) { if (g_strcmp0 (existing_ids[j], retval) == 0) { - g_free (retval); - retval = NULL; + g_clear_pointer (&retval, g_free); break; } } @@ -1387,8 +1386,7 @@ panel_profile_load_added_ids (GSList *list, if (id && id[0]) load_handler (id); - g_free (l->data); - l->data = NULL; + g_clear_pointer (&l->data, g_free); } g_slist_free (added_ids); @@ -1419,8 +1417,7 @@ panel_profile_delete_removed_ids (PanelGSettingsKeyType type, panel_profile_delete_dir (type, id); destroy_handler (id); - g_free (l->data); - l->data = NULL; + g_clear_pointer (&l->data, g_free); } g_slist_free (removed_ids); } diff --git a/mate-panel/panel-run-dialog.c b/mate-panel/panel-run-dialog.c index 9a421043..f2fd5c05 100644 --- a/mate-panel/panel-run-dialog.c +++ b/mate-panel/panel-run-dialog.c @@ -199,8 +199,7 @@ _panel_run_save_recent_programs_list (PanelRunDialog *dialog, } if (history_max_size < items_added + 1) { - g_free (items[history_max_size]); - items[history_max_size] = NULL; + g_clear_pointer (&items[history_max_size], g_free); } else { items[items_added + 1] = NULL; } @@ -221,11 +220,9 @@ panel_run_dialog_destroy (PanelRunDialog *dialog) g_object_unref (dialog->program_list_box); - g_clear_object (&(dialog->icon)); - g_free (dialog->desktop_path); - dialog->desktop_path = NULL; - g_free (dialog->item_name); - dialog->item_name = NULL; + g_clear_object (&dialog->icon); + g_clear_pointer (&dialog->desktop_path, g_free); + g_clear_pointer (&dialog->item_name, g_free); if (dialog->add_items_idle_id) g_source_remove (dialog->add_items_idle_id); @@ -235,9 +232,7 @@ panel_run_dialog_destroy (PanelRunDialog *dialog) g_source_remove (dialog->find_command_idle_id); dialog->find_command_idle_id = 0; - if (dialog->settings != NULL) - g_object_unref (dialog->settings); - dialog->settings = NULL; + g_clear_object (&dialog->settings); if (dialog->dir_hash) g_hash_table_destroy (dialog->dir_hash); @@ -1059,12 +1054,9 @@ program_list_selection_changed (GtkTreeSelection *selection, } dialog->use_program_list = TRUE; - if (dialog->desktop_path) - g_free (dialog->desktop_path); + g_free (dialog->desktop_path); dialog->desktop_path = g_strdup (path); - if (dialog->item_name) - g_free (dialog->item_name); - dialog->item_name = NULL; + g_clear_pointer (&dialog->item_name, g_free); /* Order is important here. We have to set the text first so that the * drag source is enabled, otherwise the drag icon can't be set by @@ -1846,10 +1838,8 @@ panel_run_dialog_create_desktop_file (PanelRunDialog *dialog) save_uri = panel_make_unique_desktop_uri (g_get_tmp_dir (), name); disk = g_filename_from_uri (save_uri, NULL, NULL); - if (!disk || !panel_key_file_to_file (key_file, disk, NULL)) { - g_free (save_uri); - save_uri = NULL; - } + if (!disk || !panel_key_file_to_file (key_file, disk, NULL)) + g_clear_pointer (&save_uri, g_free); g_key_file_free (key_file); g_free (disk); diff --git a/mate-panel/panel-toplevel.c b/mate-panel/panel-toplevel.c index 7f5c6cf6..c6f19c0b 100644 --- a/mate-panel/panel-toplevel.c +++ b/mate-panel/panel-toplevel.c @@ -3061,26 +3061,18 @@ panel_toplevel_dispose (GObject *widget) { PanelToplevel *toplevel = (PanelToplevel *) widget; - if (toplevel->priv->settings_path) { - g_free (toplevel->priv->settings_path); - toplevel->priv->settings_path = NULL; - } + g_clear_pointer (&toplevel->priv->settings_path, g_free); if (toplevel->settings) { g_signal_handlers_disconnect_by_data (toplevel->settings, toplevel); - g_object_unref (toplevel->settings); - toplevel->settings = NULL; + g_clear_object (&toplevel->settings); } - if (toplevel->queued_settings) { - g_object_unref (toplevel->queued_settings); - toplevel->queued_settings = NULL; - } + g_clear_object (&toplevel->queued_settings); if (toplevel->background_settings) { g_signal_handlers_disconnect_by_data (toplevel->background_settings, toplevel); - g_object_unref (toplevel->background_settings); - toplevel->background_settings = NULL; + g_clear_object (&toplevel->background_settings); } if (toplevel->priv->gtk_settings) { @@ -3100,15 +3092,8 @@ panel_toplevel_dispose (GObject *widget) toplevel->priv->attach_widget = NULL; } - if (toplevel->priv->description) { - g_free (toplevel->priv->description); - toplevel->priv->description = NULL; - } - - if (toplevel->priv->name) { - g_free (toplevel->priv->name); - toplevel->priv->name = NULL; - } + g_clear_pointer (&toplevel->priv->description, g_free); + g_clear_pointer (&toplevel->priv->name, g_free); panel_toplevel_disconnect_timeouts (toplevel); @@ -4848,12 +4833,11 @@ panel_toplevel_set_name (PanelToplevel *toplevel, !strcmp (toplevel->priv->name, name)) return; - if (toplevel->priv->name) - g_free (toplevel->priv->name); - toplevel->priv->name = NULL; - + g_free (toplevel->priv->name); if (name && name [0]) toplevel->priv->name = g_strdup (name); + else + toplevel->priv->name = NULL; panel_toplevel_update_name (toplevel); diff --git a/mate-panel/panel-widget.c b/mate-panel/panel-widget.c index 574d419b..6b4251db 100644 --- a/mate-panel/panel-widget.c +++ b/mate-panel/panel-widget.c @@ -1271,12 +1271,8 @@ panel_widget_get_preferred_size(GtkWidget *widget, } panel->nb_applets_size_hints = 0; - if (panel->applets_hints != NULL) - g_free (panel->applets_hints); - panel->applets_hints = NULL; - if (panel->applets_using_hint != NULL) - g_free (panel->applets_using_hint); - panel->applets_using_hint = NULL; + g_clear_pointer (&panel->applets_hints, g_free); + g_clear_pointer (&panel->applets_using_hint, g_free); if (panel->packed) { /* put the list in the correct order: this is important @@ -1595,12 +1591,8 @@ panel_widget_finalize (GObject *obj) panel = PANEL_WIDGET (obj); - if (panel->applets_hints != NULL) - g_free (panel->applets_hints); - panel->applets_hints = NULL; - if (panel->applets_using_hint != NULL) - g_free (panel->applets_using_hint); - panel->applets_using_hint = NULL; + g_clear_pointer (&panel->applets_hints, g_free); + g_clear_pointer (&panel->applets_using_hint, g_free); G_OBJECT_CLASS (panel_widget_parent_class)->finalize (obj); } |