mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 13:11:13 +00:00
Remove redundant checks for NULL
Remove checks for NULL before g_free() and g_clear_object(). Merge check for NULL, freeing of pointer and its setting to NULL by g_clear_pointer(). https://bugzilla.gnome.org/show_bug.cgi?id=733157
This commit is contained in:
parent
07722ae2dd
commit
8b5d30d439
@ -1387,8 +1387,7 @@ broadway_server_destroy_window (BroadwayServer *server,
|
||||
g_hash_table_remove (server->id_ht,
|
||||
GINT_TO_POINTER (id));
|
||||
|
||||
if (window->cached_surface_name != NULL)
|
||||
g_free (window->cached_surface_name);
|
||||
g_free (window->cached_surface_name);
|
||||
if (window->cached_surface != NULL)
|
||||
cairo_surface_destroy (window->cached_surface);
|
||||
|
||||
@ -1748,8 +1747,7 @@ broadway_server_open_surface (BroadwayServer *server,
|
||||
cairo_surface_set_user_data (surface, &shm_cairo_key,
|
||||
data, shm_data_unmap);
|
||||
|
||||
if (window->cached_surface_name != NULL)
|
||||
g_free (window->cached_surface_name);
|
||||
g_free (window->cached_surface_name);
|
||||
window->cached_surface_name = g_strdup (name);
|
||||
|
||||
if (window->cached_surface != NULL)
|
||||
|
@ -1129,12 +1129,7 @@ finish_drag (MoveResizeData *mv_resize)
|
||||
mv_resize->moveresize_emulation_window = NULL;
|
||||
g_object_unref (mv_resize->moveresize_window);
|
||||
mv_resize->moveresize_window = NULL;
|
||||
|
||||
if (mv_resize->moveresize_pending_event)
|
||||
{
|
||||
g_free (mv_resize->moveresize_pending_event);
|
||||
mv_resize->moveresize_pending_event = NULL;
|
||||
}
|
||||
g_clear_pointer (&mv_resize->moveresize_pending_event, g_free);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -313,8 +313,7 @@ gdk_device_set_property (GObject *object,
|
||||
device->manager = g_value_get_object (value);
|
||||
break;
|
||||
case PROP_NAME:
|
||||
if (device->name)
|
||||
g_free (device->name);
|
||||
g_free (device->name);
|
||||
|
||||
device->name = g_value_dup_string (value);
|
||||
break;
|
||||
@ -1477,8 +1476,7 @@ void
|
||||
_gdk_device_set_keys (GdkDevice *device,
|
||||
guint num_keys)
|
||||
{
|
||||
if (device->keys)
|
||||
g_free (device->keys);
|
||||
g_free (device->keys);
|
||||
|
||||
device->num_keys = num_keys;
|
||||
device->keys = g_new0 (GdkDeviceKey, num_keys);
|
||||
|
@ -125,10 +125,7 @@
|
||||
gchar *prev_str;
|
||||
markedRange = selectedRange = NSMakeRange (NSNotFound, 0);
|
||||
|
||||
prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_MARKED_TEXT);
|
||||
if (prev_str)
|
||||
g_free (prev_str);
|
||||
g_object_set_data (G_OBJECT (gdk_window), TIC_MARKED_TEXT, NULL);
|
||||
g_object_set_data_full (G_OBJECT (gdk_window), TIC_MARKED_TEXT, NULL, g_free);
|
||||
}
|
||||
|
||||
-(void)setMarkedText: (id)aString selectedRange: (NSRange)newSelection replacementRange: (NSRange)replacementRange
|
||||
@ -155,10 +152,7 @@
|
||||
str = [aString UTF8String];
|
||||
}
|
||||
|
||||
prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_MARKED_TEXT);
|
||||
if (prev_str)
|
||||
g_free (prev_str);
|
||||
g_object_set_data (G_OBJECT (gdk_window), TIC_MARKED_TEXT, g_strdup (str));
|
||||
g_object_set_data_full (G_OBJECT (gdk_window), TIC_MARKED_TEXT, g_strdup (str), g_free);
|
||||
g_object_set_data (G_OBJECT (gdk_window), TIC_SELECTED_POS,
|
||||
GUINT_TO_POINTER (selectedRange.location));
|
||||
g_object_set_data (G_OBJECT (gdk_window), TIC_SELECTED_LEN,
|
||||
@ -214,10 +208,7 @@
|
||||
str = [string UTF8String];
|
||||
}
|
||||
|
||||
prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT);
|
||||
if (prev_str)
|
||||
g_free (prev_str);
|
||||
g_object_set_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT, g_strdup (str));
|
||||
g_object_set_data_full (G_OBJECT (gdk_window), TIC_INSERT_TEXT, g_strdup (str), g_free);
|
||||
GDK_NOTE (EVENTS, g_print ("insertText: set %s (%p, nsview %p): %s\n",
|
||||
TIC_INSERT_TEXT, gdk_window, self,
|
||||
str ? str : "(empty)"));
|
||||
|
@ -245,8 +245,7 @@ select_thread_func (void *arg)
|
||||
*
|
||||
* => POLLING_DESCRIPTORS: select thread picks up the file descriptors to begin polling
|
||||
*/
|
||||
if (current_pollfds)
|
||||
g_free (current_pollfds);
|
||||
g_free (current_pollfds);
|
||||
|
||||
current_pollfds = next_pollfds;
|
||||
current_n_pollfds = next_n_pollfds;
|
||||
|
@ -107,12 +107,7 @@ static void
|
||||
gdk_quartz_screen_screen_rects_free (GdkQuartzScreen *screen)
|
||||
{
|
||||
screen->n_screens = 0;
|
||||
|
||||
if (screen->screen_rects)
|
||||
{
|
||||
g_free (screen->screen_rects);
|
||||
screen->screen_rects = NULL;
|
||||
}
|
||||
g_clear_pointer (&screen->screen_rects, g_free);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -4977,12 +4977,7 @@ finish_drag (MoveResizeData *mv_resize)
|
||||
mv_resize->moveresize_emulation_window = NULL;
|
||||
g_object_unref (mv_resize->moveresize_window);
|
||||
mv_resize->moveresize_window = NULL;
|
||||
|
||||
if (mv_resize->moveresize_pending_event)
|
||||
{
|
||||
g_free (mv_resize->moveresize_pending_event);
|
||||
mv_resize->moveresize_pending_event = NULL;
|
||||
}
|
||||
g_clear_pointer (&mv_resize->moveresize_pending_event, g_free);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -5677,8 +5672,7 @@ gdk_x11_window_set_opaque_region (GdkWindow *window,
|
||||
XA_CARDINAL, 32, PropModeReplace,
|
||||
(guchar *) data, nitems);
|
||||
|
||||
if (data != NULL)
|
||||
g_free (data);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -902,11 +902,7 @@ gtk_numerable_icon_set_background_gicon (GtkNumerableIcon *self,
|
||||
|
||||
g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
|
||||
|
||||
if (self->priv->background_icon_name != NULL)
|
||||
{
|
||||
g_free (self->priv->background_icon_name);
|
||||
self->priv->background_icon_name = NULL;
|
||||
}
|
||||
g_clear_pointer (&self->priv->background_icon_name, g_free);
|
||||
|
||||
res = real_set_background_icon (self, icon);
|
||||
|
||||
|
@ -296,8 +296,7 @@ gtk_theming_engine_impl_set_property (GObject *object,
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_NAME:
|
||||
if (priv->name)
|
||||
g_free (priv->name);
|
||||
g_free (priv->name);
|
||||
|
||||
priv->name = g_value_dup_string (value);
|
||||
break;
|
||||
|
@ -531,11 +531,7 @@ gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
|
||||
static void
|
||||
gtk_accel_label_reset (GtkAccelLabel *accel_label)
|
||||
{
|
||||
if (accel_label->priv->accel_string)
|
||||
{
|
||||
g_free (accel_label->priv->accel_string);
|
||||
accel_label->priv->accel_string = NULL;
|
||||
}
|
||||
g_clear_pointer (&accel_label->priv->accel_string, g_free);
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (accel_label));
|
||||
}
|
||||
@ -893,11 +889,7 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label)
|
||||
|
||||
g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
|
||||
|
||||
if (accel_label->priv->accel_string)
|
||||
{
|
||||
g_free (accel_label->priv->accel_string);
|
||||
accel_label->priv->accel_string = NULL;
|
||||
}
|
||||
g_clear_pointer (&accel_label->priv->accel_string, g_free);
|
||||
|
||||
g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
|
||||
"gtk-enable-accels", &enable_accels,
|
||||
|
@ -692,11 +692,7 @@ gtk_button_destroy (GtkWidget *widget)
|
||||
GtkButton *button = GTK_BUTTON (widget);
|
||||
GtkButtonPrivate *priv = button->priv;
|
||||
|
||||
if (priv->label_text)
|
||||
{
|
||||
g_free (priv->label_text);
|
||||
priv->label_text = NULL;
|
||||
}
|
||||
g_clear_pointer (&priv->label_text, g_free);
|
||||
|
||||
g_clear_object (&priv->gesture);
|
||||
|
||||
|
@ -9280,8 +9280,7 @@ gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
|
||||
if ((icon_info = priv->icons[icon_pos]) == NULL)
|
||||
icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
|
||||
|
||||
if (icon_info->tooltip)
|
||||
g_free (icon_info->tooltip);
|
||||
g_free (icon_info->tooltip);
|
||||
|
||||
/* Treat an empty string as a NULL string,
|
||||
* because an empty string would be useless for a tooltip:
|
||||
@ -9363,8 +9362,7 @@ gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
|
||||
if ((icon_info = priv->icons[icon_pos]) == NULL)
|
||||
icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
|
||||
|
||||
if (icon_info->tooltip)
|
||||
g_free (icon_info->tooltip);
|
||||
g_free (icon_info->tooltip);
|
||||
|
||||
/* Treat an empty string as a NULL string,
|
||||
* because an empty string would be useless for a tooltip:
|
||||
|
@ -1133,8 +1133,7 @@ gtk_menu_destroy (GtkWidget *widget)
|
||||
|
||||
gtk_menu_stop_navigating_submenu (menu);
|
||||
|
||||
if (priv->old_active_menu_item)
|
||||
g_clear_object (&priv->old_active_menu_item);
|
||||
g_clear_object (&priv->old_active_menu_item);
|
||||
|
||||
/* Add back the reference count for being a child */
|
||||
if (priv->needs_destruction_ref)
|
||||
@ -1143,8 +1142,7 @@ gtk_menu_destroy (GtkWidget *widget)
|
||||
g_object_ref (widget);
|
||||
}
|
||||
|
||||
if (priv->accel_group)
|
||||
g_clear_object (&priv->accel_group);
|
||||
g_clear_object (&priv->accel_group);
|
||||
|
||||
if (priv->toplevel)
|
||||
gtk_widget_destroy (priv->toplevel);
|
||||
@ -1152,17 +1150,9 @@ gtk_menu_destroy (GtkWidget *widget)
|
||||
if (priv->tearoff_window)
|
||||
gtk_widget_destroy (priv->tearoff_window);
|
||||
|
||||
if (priv->heights)
|
||||
{
|
||||
g_free (priv->heights);
|
||||
priv->heights = NULL;
|
||||
}
|
||||
g_clear_pointer (&priv->heights, g_free);
|
||||
|
||||
if (priv->title)
|
||||
{
|
||||
g_free (priv->title);
|
||||
priv->title = NULL;
|
||||
}
|
||||
g_clear_pointer (&priv->title, g_free);
|
||||
|
||||
if (priv->position_func_data_destroy)
|
||||
{
|
||||
|
@ -661,11 +661,7 @@ printer_changed_callback (GtkComboBox *combo_box,
|
||||
/* If we're waiting for a specific printer but the user changed
|
||||
* to another printer, cancel that wait.
|
||||
*/
|
||||
if (priv->waiting_for_printer)
|
||||
{
|
||||
g_free (priv->waiting_for_printer);
|
||||
priv->waiting_for_printer = NULL;
|
||||
}
|
||||
g_clear_pointer (&priv->waiting_for_printer, g_free);
|
||||
|
||||
if (priv->request_details_tag)
|
||||
{
|
||||
|
@ -3781,8 +3781,7 @@ cups_parse_user_default_printer (const char *filename,
|
||||
|
||||
*lineptr = '\0';
|
||||
|
||||
if (*printer_name != NULL)
|
||||
g_free (*printer_name);
|
||||
g_free (*printer_name);
|
||||
|
||||
*printer_name = g_strdup (defname);
|
||||
}
|
||||
|
@ -51,8 +51,7 @@ notify_cb (GObject *obj,
|
||||
GParamSpec *pspec, NotifyData *data)
|
||||
{
|
||||
data->count++;
|
||||
if (data->last_name)
|
||||
g_free (data->last_name);
|
||||
g_free (data->last_name);
|
||||
data->last_name = g_strdup (pspec->name);
|
||||
}
|
||||
|
||||
|
@ -170,8 +170,7 @@ compare_filename_cb (GtkFileChooser *chooser, gpointer data)
|
||||
|
||||
g_assert_cmpstr (out_filename, ==, filename);
|
||||
|
||||
if (out_filename)
|
||||
g_free (out_filename);
|
||||
g_free (out_filename);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
|
@ -6205,8 +6205,7 @@ specific_bug_621076_visible_func (GtkTreeModel *model,
|
||||
}
|
||||
}
|
||||
|
||||
if (str)
|
||||
g_free (str);
|
||||
g_free (str);
|
||||
|
||||
return visible;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user