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,8 +1387,7 @@ broadway_server_destroy_window (BroadwayServer *server,
g_hash_table_remove (server->id_ht, g_hash_table_remove (server->id_ht,
GINT_TO_POINTER (id)); 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) if (window->cached_surface != NULL)
cairo_surface_destroy (window->cached_surface); 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, cairo_surface_set_user_data (surface, &shm_cairo_key,
data, shm_data_unmap); 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); window->cached_surface_name = g_strdup (name);
if (window->cached_surface != NULL) if (window->cached_surface != NULL)

View File

@ -1129,12 +1129,7 @@ finish_drag (MoveResizeData *mv_resize)
mv_resize->moveresize_emulation_window = NULL; mv_resize->moveresize_emulation_window = NULL;
g_object_unref (mv_resize->moveresize_window); g_object_unref (mv_resize->moveresize_window);
mv_resize->moveresize_window = NULL; mv_resize->moveresize_window = NULL;
g_clear_pointer (&mv_resize->moveresize_pending_event, g_free);
if (mv_resize->moveresize_pending_event)
{
g_free (mv_resize->moveresize_pending_event);
mv_resize->moveresize_pending_event = NULL;
}
} }
static gboolean static gboolean

View File

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

View File

@ -125,10 +125,7 @@
gchar *prev_str; gchar *prev_str;
markedRange = selectedRange = NSMakeRange (NSNotFound, 0); markedRange = selectedRange = NSMakeRange (NSNotFound, 0);
prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_MARKED_TEXT); g_object_set_data_full (G_OBJECT (gdk_window), TIC_MARKED_TEXT, NULL, g_free);
if (prev_str)
g_free (prev_str);
g_object_set_data (G_OBJECT (gdk_window), TIC_MARKED_TEXT, NULL);
} }
-(void)setMarkedText: (id)aString selectedRange: (NSRange)newSelection replacementRange: (NSRange)replacementRange -(void)setMarkedText: (id)aString selectedRange: (NSRange)newSelection replacementRange: (NSRange)replacementRange
@ -155,10 +152,7 @@
str = [aString UTF8String]; str = [aString UTF8String];
} }
prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_MARKED_TEXT); g_object_set_data_full (G_OBJECT (gdk_window), TIC_MARKED_TEXT, g_strdup (str), g_free);
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 (G_OBJECT (gdk_window), TIC_SELECTED_POS, g_object_set_data (G_OBJECT (gdk_window), TIC_SELECTED_POS,
GUINT_TO_POINTER (selectedRange.location)); GUINT_TO_POINTER (selectedRange.location));
g_object_set_data (G_OBJECT (gdk_window), TIC_SELECTED_LEN, g_object_set_data (G_OBJECT (gdk_window), TIC_SELECTED_LEN,
@ -214,10 +208,7 @@
str = [string UTF8String]; str = [string UTF8String];
} }
prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT); g_object_set_data_full (G_OBJECT (gdk_window), TIC_INSERT_TEXT, g_strdup (str), g_free);
if (prev_str)
g_free (prev_str);
g_object_set_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT, g_strdup (str));
GDK_NOTE (EVENTS, g_print ("insertText: set %s (%p, nsview %p): %s\n", GDK_NOTE (EVENTS, g_print ("insertText: set %s (%p, nsview %p): %s\n",
TIC_INSERT_TEXT, gdk_window, self, TIC_INSERT_TEXT, gdk_window, self,
str ? str : "(empty)")); str ? str : "(empty)"));

View File

@ -245,8 +245,7 @@ select_thread_func (void *arg)
* *
* => POLLING_DESCRIPTORS: select thread picks up the file descriptors to begin polling * => 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_pollfds = next_pollfds;
current_n_pollfds = next_n_pollfds; current_n_pollfds = next_n_pollfds;

View File

@ -107,12 +107,7 @@ static void
gdk_quartz_screen_screen_rects_free (GdkQuartzScreen *screen) gdk_quartz_screen_screen_rects_free (GdkQuartzScreen *screen)
{ {
screen->n_screens = 0; screen->n_screens = 0;
g_clear_pointer (&screen->screen_rects, g_free);
if (screen->screen_rects)
{
g_free (screen->screen_rects);
screen->screen_rects = NULL;
}
} }
static void static void

View File

@ -4977,12 +4977,7 @@ finish_drag (MoveResizeData *mv_resize)
mv_resize->moveresize_emulation_window = NULL; mv_resize->moveresize_emulation_window = NULL;
g_object_unref (mv_resize->moveresize_window); g_object_unref (mv_resize->moveresize_window);
mv_resize->moveresize_window = NULL; mv_resize->moveresize_window = NULL;
g_clear_pointer (&mv_resize->moveresize_pending_event, g_free);
if (mv_resize->moveresize_pending_event)
{
g_free (mv_resize->moveresize_pending_event);
mv_resize->moveresize_pending_event = NULL;
}
} }
static int static int
@ -5677,8 +5672,7 @@ gdk_x11_window_set_opaque_region (GdkWindow *window,
XA_CARDINAL, 32, PropModeReplace, XA_CARDINAL, 32, PropModeReplace,
(guchar *) data, nitems); (guchar *) data, nitems);
if (data != NULL) g_free (data);
g_free (data);
} }
static gboolean static gboolean

View File

@ -902,11 +902,7 @@ gtk_numerable_icon_set_background_gicon (GtkNumerableIcon *self,
g_return_if_fail (GTK_IS_NUMERABLE_ICON (self)); g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
if (self->priv->background_icon_name != NULL) g_clear_pointer (&self->priv->background_icon_name, g_free);
{
g_free (self->priv->background_icon_name);
self->priv->background_icon_name = NULL;
}
res = real_set_background_icon (self, icon); res = real_set_background_icon (self, icon);

View File

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

View File

@ -531,11 +531,7 @@ gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
static void static void
gtk_accel_label_reset (GtkAccelLabel *accel_label) gtk_accel_label_reset (GtkAccelLabel *accel_label)
{ {
if (accel_label->priv->accel_string) g_clear_pointer (&accel_label->priv->accel_string, g_free);
{
g_free (accel_label->priv->accel_string);
accel_label->priv->accel_string = NULL;
}
gtk_widget_queue_resize (GTK_WIDGET (accel_label)); 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); g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
if (accel_label->priv->accel_string) g_clear_pointer (&accel_label->priv->accel_string, g_free);
{
g_free (accel_label->priv->accel_string);
accel_label->priv->accel_string = NULL;
}
g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)), g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
"gtk-enable-accels", &enable_accels, "gtk-enable-accels", &enable_accels,

View File

@ -692,11 +692,7 @@ gtk_button_destroy (GtkWidget *widget)
GtkButton *button = GTK_BUTTON (widget); GtkButton *button = GTK_BUTTON (widget);
GtkButtonPrivate *priv = button->priv; GtkButtonPrivate *priv = button->priv;
if (priv->label_text) g_clear_pointer (&priv->label_text, g_free);
{
g_free (priv->label_text);
priv->label_text = NULL;
}
g_clear_object (&priv->gesture); g_clear_object (&priv->gesture);

View File

@ -9280,8 +9280,7 @@ gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
if ((icon_info = priv->icons[icon_pos]) == NULL) if ((icon_info = priv->icons[icon_pos]) == NULL)
icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos); 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, /* Treat an empty string as a NULL string,
* because an empty string would be useless for a tooltip: * 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) if ((icon_info = priv->icons[icon_pos]) == NULL)
icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos); 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, /* Treat an empty string as a NULL string,
* because an empty string would be useless for a tooltip: * because an empty string would be useless for a tooltip:

View File

@ -1133,8 +1133,7 @@ gtk_menu_destroy (GtkWidget *widget)
gtk_menu_stop_navigating_submenu (menu); 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 */ /* Add back the reference count for being a child */
if (priv->needs_destruction_ref) if (priv->needs_destruction_ref)
@ -1143,8 +1142,7 @@ gtk_menu_destroy (GtkWidget *widget)
g_object_ref (widget); g_object_ref (widget);
} }
if (priv->accel_group) g_clear_object (&priv->accel_group);
g_clear_object (&priv->accel_group);
if (priv->toplevel) if (priv->toplevel)
gtk_widget_destroy (priv->toplevel); gtk_widget_destroy (priv->toplevel);
@ -1152,17 +1150,9 @@ gtk_menu_destroy (GtkWidget *widget)
if (priv->tearoff_window) if (priv->tearoff_window)
gtk_widget_destroy (priv->tearoff_window); gtk_widget_destroy (priv->tearoff_window);
if (priv->heights) g_clear_pointer (&priv->heights, g_free);
{
g_free (priv->heights);
priv->heights = NULL;
}
if (priv->title) g_clear_pointer (&priv->title, g_free);
{
g_free (priv->title);
priv->title = NULL;
}
if (priv->position_func_data_destroy) 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 /* If we're waiting for a specific printer but the user changed
* to another printer, cancel that wait. * to another printer, cancel that wait.
*/ */
if (priv->waiting_for_printer) g_clear_pointer (&priv->waiting_for_printer, g_free);
{
g_free (priv->waiting_for_printer);
priv->waiting_for_printer = NULL;
}
if (priv->request_details_tag) if (priv->request_details_tag)
{ {

View File

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

View File

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

View File

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

View File

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