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:
Marek Kasik 2014-07-14 17:02:13 +02:00
parent 07722ae2dd
commit 8b5d30d439
18 changed files with 28 additions and 95 deletions

View File

@ -1387,7 +1387,6 @@ 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);
if (window->cached_surface != NULL)
cairo_surface_destroy (window->cached_surface);
@ -1748,7 +1747,6 @@ 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);
window->cached_surface_name = g_strdup (name);

View File

@ -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

View File

@ -313,7 +313,6 @@ gdk_device_set_property (GObject *object,
device->manager = g_value_get_object (value);
break;
case PROP_NAME:
if (device->name)
g_free (device->name);
device->name = g_value_dup_string (value);
@ -1477,7 +1476,6 @@ void
_gdk_device_set_keys (GdkDevice *device,
guint num_keys)
{
if (device->keys)
g_free (device->keys);
device->num_keys = num_keys;

View File

@ -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)"));

View File

@ -245,7 +245,6 @@ select_thread_func (void *arg)
*
* => POLLING_DESCRIPTORS: select thread picks up the file descriptors to begin polling
*/
if (current_pollfds)
g_free (current_pollfds);
current_pollfds = next_pollfds;

View File

@ -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

View File

@ -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,7 +5672,6 @@ gdk_x11_window_set_opaque_region (GdkWindow *window,
XA_CARDINAL, 32, PropModeReplace,
(guchar *) data, nitems);
if (data != NULL)
g_free (data);
}

View File

@ -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);

View File

@ -296,7 +296,6 @@ gtk_theming_engine_impl_set_property (GObject *object,
switch (prop_id)
{
case PROP_NAME:
if (priv->name)
g_free (priv->name);
priv->name = g_value_dup_string (value);

View File

@ -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,

View File

@ -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);

View File

@ -9280,7 +9280,6 @@ 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);
/* Treat an empty string as a NULL string,
@ -9363,7 +9362,6 @@ 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);
/* Treat an empty string as a NULL string,

View File

@ -1133,7 +1133,6 @@ 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);
/* Add back the reference count for being a child */
@ -1143,7 +1142,6 @@ gtk_menu_destroy (GtkWidget *widget)
g_object_ref (widget);
}
if (priv->accel_group)
g_clear_object (&priv->accel_group);
if (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)
{

View File

@ -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)
{

View File

@ -3781,7 +3781,6 @@ cups_parse_user_default_printer (const char *filename,
*lineptr = '\0';
if (*printer_name != NULL)
g_free (*printer_name);
*printer_name = g_strdup (defname);

View File

@ -51,7 +51,6 @@ notify_cb (GObject *obj,
GParamSpec *pspec, NotifyData *data)
{
data->count++;
if (data->last_name)
g_free (data->last_name);
data->last_name = g_strdup (pspec->name);
}

View File

@ -170,7 +170,6 @@ compare_filename_cb (GtkFileChooser *chooser, gpointer data)
g_assert_cmpstr (out_filename, ==, filename);
if (out_filename)
g_free (out_filename);
}

View File

@ -6205,7 +6205,6 @@ specific_bug_621076_visible_func (GtkTreeModel *model,
}
}
if (str)
g_free (str);
return visible;