app: use g_clear_pointer() in more places

This commit is contained in:
Michael Natterer 2019-05-27 17:47:55 +02:00
parent 9fa49af470
commit 901350ba20
35 changed files with 124 additions and 320 deletions

View File

@ -149,11 +149,8 @@ gimp_lang_rc_finalize (GObject *object)
g_clear_object (&rc->system_gimprc);
g_clear_object (&rc->user_gimprc);
if (rc->language)
{
g_free (rc->language);
rc->language = NULL;
}
g_clear_pointer (&rc->language, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -121,8 +121,7 @@ gimp_brush_pipe_finalize (GObject *object)
if (pipe->brushes[i])
g_object_unref (pipe->brushes[i]);
g_free (pipe->brushes);
pipe->brushes = NULL;
g_clear_pointer (&pipe->brushes, g_free);
}
GIMP_BRUSH (pipe)->priv->mask = NULL;

View File

@ -350,17 +350,8 @@ gimp_channel_finalize (GObject *object)
{
GimpChannel *channel = GIMP_CHANNEL (object);
if (channel->segs_in)
{
g_free (channel->segs_in);
channel->segs_in = NULL;
}
if (channel->segs_out)
{
g_free (channel->segs_out);
channel->segs_out = NULL;
}
g_clear_pointer (&channel->segs_in, g_free);
g_clear_pointer (&channel->segs_out, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -1166,14 +1157,10 @@ gimp_channel_real_is_empty (GimpChannel *channel)
return FALSE;
/* The mask is empty, meaning we can set the bounds as known */
if (channel->segs_in)
g_free (channel->segs_in);
if (channel->segs_out)
g_free (channel->segs_out);
g_clear_pointer (&channel->segs_in, g_free);
g_clear_pointer (&channel->segs_out, g_free);
channel->empty = TRUE;
channel->segs_in = NULL;
channel->segs_out = NULL;
channel->num_segs_in = 0;
channel->num_segs_out = 0;
channel->bounds_known = TRUE;

View File

@ -224,17 +224,11 @@ gimp_curve_finalize (GObject *object)
{
GimpCurve *curve = GIMP_CURVE (object);
if (curve->points)
{
g_free (curve->points);
curve->points = NULL;
}
g_clear_pointer (&curve->points, g_free);
curve->n_points = 0;
if (curve->samples)
{
g_free (curve->samples);
curve->samples = NULL;
}
g_clear_pointer (&curve->samples, g_free);
curve->n_samples = 0;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -1043,8 +1037,8 @@ gimp_curve_clear_points (GimpCurve *curve)
if (curve->points)
{
curve->n_points = 0;
g_clear_pointer (&curve->points, g_free);
curve->n_points = 0;
g_object_notify (G_OBJECT (curve), "n-points");
g_object_notify (G_OBJECT (curve), "points");

View File

@ -370,8 +370,7 @@ gimp_histogram_clear_values (GimpHistogram *histogram)
if (histogram->priv->values)
{
g_free (histogram->priv->values);
histogram->priv->values = NULL;
g_clear_pointer (&histogram->priv->values, g_free);
g_object_notify (G_OBJECT (histogram), "values");
}

View File

@ -2507,8 +2507,7 @@ gimp_layer_set_floating_sel_drawable (GimpLayer *layer,
{
if (layer->fs.segs)
{
g_free (layer->fs.segs);
layer->fs.segs = NULL;
g_clear_pointer (&layer->fs.segs, g_free);
layer->fs.num_segs = 0;
}

View File

@ -109,11 +109,7 @@ gimp_mybrush_finalize (GObject *object)
{
GimpMybrush *brush = GIMP_MYBRUSH (object);
if (brush->priv->brush_json)
{
g_free (brush->priv->brush_json);
brush->priv->brush_json = NULL;
}
g_clear_pointer (&brush->priv->brush_json, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -1254,8 +1254,7 @@ gimp_viewable_set_icon_name (GimpViewable *viewable,
private = GET_PRIVATE (viewable);
g_free (private->icon_name);
private->icon_name = NULL;
g_clear_pointer (&private->icon_name, g_free);
viewable_class = GIMP_VIEWABLE_GET_CLASS (viewable);

View File

@ -130,18 +130,10 @@ gimp_canvas_boundary_finalize (GObject *object)
{
GimpCanvasBoundaryPrivate *private = GET_PRIVATE (object);
if (private->segs)
{
g_free (private->segs);
private->segs = NULL;
private->n_segs = 0;
}
g_clear_pointer (&private->segs, g_free);
private->n_segs = 0;
if (private->transform)
{
g_free (private->transform);
private->transform = NULL;
}
g_clear_pointer (&private->transform, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -121,18 +121,10 @@ gimp_canvas_polygon_finalize (GObject *object)
{
GimpCanvasPolygonPrivate *private = GET_PRIVATE (object);
if (private->points)
{
g_free (private->points);
private->points = NULL;
private->n_points = 0;
}
g_clear_pointer (&private->points, g_free);
private->n_points = 0;
if (private->transform)
{
g_free (private->transform);
private->transform = NULL;
}
g_clear_pointer (&private->transform, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -151,8 +143,7 @@ gimp_canvas_polygon_set_property (GObject *object,
{
GimpArray *array = g_value_get_boxed (value);
g_free (private->points);
private->points = NULL;
g_clear_pointer (&private->points, g_free);
private->n_points = 0;
if (array)

View File

@ -173,11 +173,7 @@ gimp_canvas_progress_finalize (GObject *object)
{
GimpCanvasProgressPrivate *private = GET_PRIVATE (object);
if (private->text)
{
g_free (private->text);
private->text = NULL;
}
g_clear_pointer (&private->text, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -819,11 +819,7 @@ gimp_tool_rectangle_finalize (GObject *object)
GimpToolRectangle *rectangle = GIMP_TOOL_RECTANGLE (object);
GimpToolRectanglePrivate *private = rectangle->private;
if (private->status_title)
{
g_free (private->status_title);
private->status_title = NULL;
}
g_clear_pointer (&private->status_title, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -120,8 +120,7 @@ gimp_procedure_finalize (GObject *object)
for (i = 0; i < procedure->num_args; i++)
g_param_spec_unref (procedure->args[i]);
g_free (procedure->args);
procedure->args = NULL;
g_clear_pointer (&procedure->args, g_free);
}
if (procedure->values)
@ -129,8 +128,7 @@ gimp_procedure_finalize (GObject *object)
for (i = 0; i < procedure->num_values; i++)
g_param_spec_unref (procedure->values[i]);
g_free (procedure->values);
procedure->values = NULL;
g_clear_pointer (&procedure->values, g_free);
}
G_OBJECT_CLASS (parent_class)->finalize (object);

View File

@ -318,26 +318,10 @@ gimp_text_finalize (GObject *object)
{
GimpText *text = GIMP_TEXT (object);
if (text->text)
{
g_free (text->text);
text->text = NULL;
}
if (text->markup)
{
g_free (text->markup);
text->markup = NULL;
}
if (text->font)
{
g_free (text->font);
text->font = NULL;
}
if (text->language)
{
g_free (text->language);
text->language = NULL;
}
g_clear_pointer (&text->text, g_free);
g_clear_pointer (&text->markup, g_free);
g_clear_pointer (&text->font, g_free);
g_clear_pointer (&text->language, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -448,8 +432,7 @@ gimp_text_set_property (GObject *object,
text->text = g_value_dup_string (value);
if (text->text && text->markup)
{
g_free (text->markup);
text->markup = NULL;
g_clear_pointer (&text->markup, g_free);
g_object_notify (object, "markup");
}
break;
@ -458,8 +441,7 @@ gimp_text_set_property (GObject *object,
text->markup = g_value_dup_string (value);
if (text->markup && text->text)
{
g_free (text->text);
text->text = NULL;
g_clear_pointer (&text->text, g_free);
g_object_notify (object, "text");
}
break;

View File

@ -186,31 +186,14 @@ gimp_edit_selection_tool_finalize (GObject *object)
{
GimpEditSelectionTool *edit_select = GIMP_EDIT_SELECTION_TOOL (object);
if (edit_select->segs_in)
{
g_free (edit_select->segs_in);
edit_select->segs_in = NULL;
edit_select->num_segs_in = 0;
}
g_clear_pointer (&edit_select->segs_in, g_free);
edit_select->num_segs_in = 0;
if (edit_select->segs_out)
{
g_free (edit_select->segs_out);
edit_select->segs_out = NULL;
edit_select->num_segs_out = 0;
}
g_clear_pointer (&edit_select->segs_out, g_free);
edit_select->num_segs_out = 0;
if (edit_select->live_items)
{
g_list_free (edit_select->live_items);
edit_select->live_items = NULL;
}
if (edit_select->delayed_items)
{
g_list_free (edit_select->delayed_items);
edit_select->delayed_items = NULL;
}
g_clear_pointer (&edit_select->live_items, g_list_free);
g_clear_pointer (&edit_select->delayed_items, g_list_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -245,11 +245,7 @@ gimp_text_options_finalize (GObject *object)
{
GimpTextOptions *options = GIMP_TEXT_OPTIONS (object);
if (options->language)
{
g_free (options->language);
options->language = NULL;
}
g_clear_pointer (&options->language, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -1711,8 +1711,7 @@ gimp_text_tool_im_delete_preedit (GimpTextTool *text_tool)
text_tool->preedit_end = NULL;
}
g_free (text_tool->preedit_string);
text_tool->preedit_string = NULL;
g_clear_pointer (&text_tool->preedit_string, g_free);
}
}

View File

@ -190,17 +190,8 @@ gimp_action_group_finalize (GObject *object)
{
GimpActionGroup *group = GIMP_ACTION_GROUP (object);
if (group->label)
{
g_free (group->label);
group->label = NULL;
}
if (group->icon_name)
{
g_free (group->icon_name);
group->icon_name = NULL;
}
g_clear_pointer (&group->label, g_free);
g_clear_pointer (&group->icon_name, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -356,8 +356,7 @@ gimp_action_view_set_filter (GimpActionView *view,
if (filter && ! strlen (filter))
filter = NULL;
g_free (view->filter);
view->filter = NULL;
g_clear_pointer (&view->filter, g_free);
if (filter)
view->filter = g_utf8_casefold (filter, -1);

View File

@ -191,10 +191,9 @@ gimp_color_history_finalize (GObject *object)
g_signal_handlers_disconnect_by_func (history->active_image,
G_CALLBACK (gimp_color_history_palette_dirty),
history);
g_free (history->color_areas);
history->color_areas = NULL;
g_free (history->buttons);
history->buttons = NULL;
g_clear_pointer (&history->color_areas, g_free);
g_clear_pointer (&history->buttons, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -214,6 +213,7 @@ gimp_color_history_set_property (GObject *object,
g_signal_handlers_disconnect_by_func (history->context,
gimp_color_history_image_changed,
history);
if (history->active_image)
{
g_signal_handlers_disconnect_by_func (history->active_image,
@ -221,13 +221,17 @@ gimp_color_history_set_property (GObject *object,
history);
history->active_image = NULL;
}
history->context = g_value_get_object (value);
if (history->context)
{
g_signal_connect (history->context, "image-changed",
G_CALLBACK (gimp_color_history_image_changed),
history);
history->active_image = gimp_context_get_image (history->context);
if (history->active_image)
{
g_signal_connect_swapped (history->active_image, "notify::base-type",
@ -241,56 +245,57 @@ gimp_color_history_set_property (GObject *object,
break;
case PROP_HISTORY_SIZE:
{
GtkWidget *button;
GtkWidget *color_area;
gint i;
{
GtkWidget *button;
GtkWidget *color_area;
gint i;
history->history_size = g_value_get_int (value);
history->history_size = g_value_get_int (value);
/* Destroy previous color buttons. */
gtk_container_foreach (GTK_CONTAINER (history),
(GtkCallback) gtk_widget_destroy, NULL);
history->buttons = g_realloc_n (history->buttons,
history->history_size,
sizeof (GtkWidget*));
history->color_areas = g_realloc_n (history->color_areas,
history->history_size,
sizeof (GtkWidget*));
for (i = 0; i < history->history_size; i++)
{
GimpRGB black = { 0.0, 0.0, 0.0, 1.0 };
gint row, column;
/* Destroy previous color buttons. */
gtk_container_foreach (GTK_CONTAINER (history),
(GtkCallback) gtk_widget_destroy, NULL);
history->buttons = g_realloc_n (history->buttons,
history->history_size,
sizeof (GtkWidget*));
history->color_areas = g_realloc_n (history->color_areas,
history->history_size,
sizeof (GtkWidget*));
column = i % (history->history_size / history->n_rows);
row = i / (history->history_size / history->n_rows);
for (i = 0; i < history->history_size; i++)
{
GimpRGB black = { 0.0, 0.0, 0.0, 1.0 };
gint row, column;
button = gtk_button_new ();
gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE);
gtk_grid_attach (GTK_GRID (history), button, column, row, 1, 1);
gtk_widget_show (button);
column = i % (history->history_size / history->n_rows);
row = i / (history->history_size / history->n_rows);
color_area = gimp_color_area_new (&black, GIMP_COLOR_AREA_SMALL_CHECKS,
GDK_BUTTON2_MASK);
gimp_color_area_set_color_config (GIMP_COLOR_AREA (color_area),
history->context->gimp->config->color_management);
gtk_container_add (GTK_CONTAINER (button), color_area);
gtk_widget_show (color_area);
button = gtk_button_new ();
gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE);
gtk_grid_attach (GTK_GRID (history), button, column, row, 1, 1);
gtk_widget_show (button);
g_signal_connect (button, "clicked",
G_CALLBACK (gimp_color_history_color_clicked),
history);
color_area = gimp_color_area_new (&black, GIMP_COLOR_AREA_SMALL_CHECKS,
GDK_BUTTON2_MASK);
gimp_color_area_set_color_config (GIMP_COLOR_AREA (color_area),
history->context->gimp->config->color_management);
gtk_container_add (GTK_CONTAINER (button), color_area);
gtk_widget_show (color_area);
g_signal_connect (color_area, "color-changed",
G_CALLBACK (gimp_color_history_color_changed),
GINT_TO_POINTER (i));
g_signal_connect (button, "clicked",
G_CALLBACK (gimp_color_history_color_clicked),
history);
history->buttons[i] = button;
history->color_areas[i] = color_area;
}
g_signal_connect (color_area, "color-changed",
G_CALLBACK (gimp_color_history_color_changed),
GINT_TO_POINTER (i));
gimp_color_history_palette_dirty (history);
}
history->buttons[i] = button;
history->color_areas[i] = color_area;
}
gimp_color_history_palette_dirty (history);
}
break;
default:

View File

@ -163,31 +163,10 @@ gimp_dockable_dispose (GObject *object)
if (dockable->p->context)
gimp_dockable_set_context (dockable, NULL);
if (dockable->p->blurb)
{
if (dockable->p->blurb != dockable->p->name)
g_free (dockable->p->blurb);
dockable->p->blurb = NULL;
}
if (dockable->p->name)
{
g_free (dockable->p->name);
dockable->p->name = NULL;
}
if (dockable->p->icon_name)
{
g_free (dockable->p->icon_name);
dockable->p->icon_name = NULL;
}
if (dockable->p->help_id)
{
g_free (dockable->p->help_id);
dockable->p->help_id = NULL;
}
g_clear_pointer (&dockable->p->blurb, g_free);
g_clear_pointer (&dockable->p->name, g_free);
g_clear_pointer (&dockable->p->icon_name, g_free);
g_clear_pointer (&dockable->p->help_id, g_free);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@ -382,7 +361,7 @@ gimp_dockable_new (const gchar *name,
if (blurb)
dockable->p->blurb = g_strdup (blurb);
else
dockable->p->blurb = dockable->p->name;
dockable->p->blurb = g_strdup (dockable->p->name);
gimp_help_set_help_data (GTK_WIDGET (dockable), NULL, help_id);

View File

@ -378,25 +378,11 @@ gimp_file_dialog_dispose (GObject *object)
dialog->progress = NULL;
if (dialog->help_id)
g_free (dialog->help_id);
dialog->help_id = NULL;
if (dialog->ok_button_label)
g_free (dialog->ok_button_label);
dialog->ok_button_label = NULL;
if (dialog->automatic_help_id)
g_free (dialog->automatic_help_id);
dialog->automatic_help_id = NULL;
if (dialog->automatic_label)
g_free (dialog->automatic_label);
dialog->automatic_label = NULL;
if (dialog->file_filter_label)
g_free (dialog->file_filter_label);
dialog->file_filter_label = NULL;
g_clear_pointer (&dialog->help_id, g_free);
g_clear_pointer (&dialog->ok_button_label, g_free);
g_clear_pointer (&dialog->automatic_help_id, g_free);
g_clear_pointer (&dialog->automatic_label, g_free);
g_clear_pointer (&dialog->file_filter_label, g_free);
}
static gboolean

View File

@ -143,12 +143,7 @@ gimp_image_parasite_view_finalize (GObject *object)
{
GimpImageParasiteView *view = GIMP_IMAGE_PARASITE_VIEW (object);
if (view->parasite)
{
g_free (view->parasite);
view->parasite = NULL;
}
g_clear_pointer (&view->parasite, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -226,11 +226,7 @@ gimp_language_entry_set_code (GimpLanguageEntry *entry,
g_return_val_if_fail (GIMP_IS_LANGUAGE_ENTRY (entry), FALSE);
if (entry->code)
{
g_free (entry->code);
entry->code = NULL;
}
g_clear_pointer (&entry->code, g_free);
if (! code || ! strlen (code))
{

View File

@ -208,15 +208,13 @@ gimp_message_box_finalize (GObject *object)
GimpMessageBox *box = GIMP_MESSAGE_BOX (object);
if (box->idle_id)
g_source_remove (box->idle_id);
box->idle_id = 0;
if (box->icon_name)
{
g_free (box->icon_name);
box->icon_name = NULL;
g_source_remove (box->idle_id);
box->idle_id = 0;
}
g_clear_pointer (&box->icon_name, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -286,17 +286,8 @@ gimp_overlay_dialog_finalize (GObject *object)
{
GimpOverlayDialog *dialog = GIMP_OVERLAY_DIALOG (object);
if (dialog->title)
{
g_free (dialog->title);
dialog->title = NULL;
}
if (dialog->icon_name)
{
g_free (dialog->icon_name);
dialog->icon_name = NULL;
}
g_clear_pointer (&dialog->title, g_free);
g_clear_pointer (&dialog->icon_name, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -756,8 +756,7 @@ gimp_search_popup_find_accel_label (GtkAction *action)
/* The value returned by gtk_accelerator_get_label() must be
* freed after use.
*/
g_free (accel_string);
accel_string = NULL;
g_clear_pointer (&accel_string, g_free);
}
return accel_string;

View File

@ -88,11 +88,7 @@ gimp_session_info_dock_free (GimpSessionInfoDock *dock_info)
{
g_return_if_fail (dock_info != NULL);
if (dock_info->dock_type)
{
g_free (dock_info->dock_type);
dock_info->dock_type = NULL;
}
g_clear_pointer (&dock_info->dock_type, g_free);
if (dock_info->books)
{

View File

@ -59,11 +59,7 @@ gimp_session_info_dockable_free (GimpSessionInfoDockable *info)
{
g_return_if_fail (info != NULL);
if (info->identifier)
{
g_free (info->identifier);
info->identifier = NULL;
}
g_clear_pointer (&info->identifier, g_free);
if (info->aux_info)
{

View File

@ -102,11 +102,7 @@ gimp_string_action_finalize (GObject *object)
{
GimpStringAction *action = GIMP_STRING_ACTION (object);
if (action->value)
{
g_free (action->value);
action->value = NULL;
}
g_clear_pointer (&action->value, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -220,11 +220,7 @@ gimp_tag_entry_dispose (GObject *object)
{
GimpTagEntry *entry = GIMP_TAG_ENTRY (object);
if (entry->selected_items)
{
g_list_free (entry->selected_items);
entry->selected_items = NULL;
}
g_clear_pointer (&entry->selected_items, g_list_free);
if (entry->common_tags)
{

View File

@ -391,8 +391,7 @@ gimp_tag_popup_dispose (GObject *object)
g_object_unref (popup->tag_data[i].tag);
}
g_free (popup->tag_data);
popup->tag_data = NULL;
g_clear_pointer (&popup->tag_data, g_free);
}
G_OBJECT_CLASS (parent_class)->dispose (object);

View File

@ -186,8 +186,7 @@ gimp_tool_editor_finalize (GObject *object)
g_free (priv->initial_tool_order[i]);
}
g_free (priv->initial_tool_order);
priv->initial_tool_order = NULL;
g_clear_pointer (&priv->initial_tool_order, g_free);
}
if (priv->initial_tool_visibility)

View File

@ -263,14 +263,8 @@ gimp_ui_manager_finalize (GObject *object)
g_slice_free (GimpUIManagerUIEntry, entry);
}
g_list_free (manager->registered_uis);
manager->registered_uis = NULL;
if (manager->name)
{
g_free (manager->name);
manager->name = NULL;
}
g_clear_pointer (&manager->registered_uis, g_list_free);
g_clear_pointer (&manager->name, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -116,23 +116,9 @@ gimp_viewable_button_finalize (GObject *object)
{
GimpViewableButton *button = GIMP_VIEWABLE_BUTTON (object);
if (button->dialog_identifier)
{
g_free (button->dialog_identifier);
button->dialog_identifier = NULL;
}
if (button->dialog_icon_name)
{
g_free (button->dialog_icon_name);
button->dialog_icon_name = NULL;
}
if (button->dialog_tooltip)
{
g_free (button->dialog_tooltip);
button->dialog_tooltip = NULL;
}
g_clear_pointer (&button->dialog_identifier, g_free);
g_clear_pointer (&button->dialog_icon_name, g_free);
g_clear_pointer (&button->dialog_tooltip, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}