Commit 3989c526 authored by Christian Hergert's avatar Christian Hergert

gstyle: add clear pointer helper

This is a more type enforcing form of clearing pointers
that helps catch incorrect frees.
parent b32d0b82
......@@ -1350,7 +1350,7 @@ gstyle_color_plane_destroy (GtkWidget *widget)
GstyleColorPlane *self = (GstyleColorPlane *)widget;
GstyleColorPlanePrivate *priv = gstyle_color_plane_get_instance_private (self);
g_clear_pointer (&priv->surface, cairo_surface_destroy);
gstyle_clear_pointer (&priv->surface, cairo_surface_destroy);
GTK_WIDGET_CLASS (gstyle_color_plane_parent_class)->destroy (widget);
}
......
......@@ -265,7 +265,7 @@ gstyle_color_scale_add_rgba_color_stop (GstyleColorScale *self,
self);
id_count += 1;
g_clear_pointer (&self->pattern, cairo_pattern_destroy);
gstyle_clear_pointer (&self->pattern, cairo_pattern_destroy);
if (gtk_widget_get_realized (GTK_WIDGET (self)))
gtk_widget_queue_draw (GTK_WIDGET (self));
......@@ -400,7 +400,7 @@ gstyle_color_scale_set_kind (GstyleColorScale *self,
self->data_stride);
}
g_clear_pointer (&self->pattern, cairo_pattern_destroy);
gstyle_clear_pointer (&self->pattern, cairo_pattern_destroy);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_KIND]);
if (gtk_widget_get_realized (GTK_WIDGET (self)))
......@@ -507,7 +507,7 @@ update_pattern (GstyleColorScale *self)
}
}
g_clear_pointer (&self->pattern, cairo_pattern_destroy);
gstyle_clear_pointer (&self->pattern, cairo_pattern_destroy);
self->pattern = pattern;
}
......@@ -598,13 +598,13 @@ gstyle_color_scale_finalize (GObject *object)
g_clear_object (&self->long_press_gesture);
g_clear_object (&self->default_provider);
g_clear_pointer (&self->custom_color_stops, g_sequence_free);
g_clear_pointer (&self->checkered_pattern, cairo_pattern_destroy);
g_clear_pointer (&self->pattern, cairo_pattern_destroy);
g_clear_pointer (&self->data_surface, cairo_surface_destroy);
gstyle_clear_pointer (&self->custom_color_stops, g_sequence_free);
gstyle_clear_pointer (&self->checkered_pattern, cairo_pattern_destroy);
gstyle_clear_pointer (&self->pattern, cairo_pattern_destroy);
gstyle_clear_pointer (&self->data_surface, cairo_surface_destroy);
g_clear_pointer (&self->data_raw, g_free);
g_clear_pointer (&self->data_raw_filtered, g_free);
gstyle_clear_pointer (&self->data_raw, g_free);
gstyle_clear_pointer (&self->data_raw_filtered, g_free);
G_OBJECT_CLASS (gstyle_color_scale_parent_class)->finalize (object);
}
......
......@@ -1351,8 +1351,8 @@ gstyle_color_widget_finalize (GObject *object)
g_clear_object (&self->filtered_color);
g_clear_object (&self->default_provider);
g_clear_pointer (&self->checkered_pattern, cairo_pattern_destroy);
g_clear_pointer (&self->target_list, gtk_target_list_unref);
gstyle_clear_pointer (&self->checkered_pattern, cairo_pattern_destroy);
gstyle_clear_pointer (&self->target_list, gtk_target_list_unref);
G_OBJECT_CLASS (gstyle_color_widget_parent_class)->finalize (object);
}
......
......@@ -1213,7 +1213,7 @@ gstyle_color_finalize (GObject *object)
{
GstyleColor *self = GSTYLE_COLOR (object);
g_clear_pointer (&self->name, g_free);
gstyle_clear_pointer (&self->name, g_free);
G_OBJECT_CLASS (gstyle_color_parent_class)->finalize (object);
}
......
......@@ -123,7 +123,7 @@ gstyle_palette_xml_get_header (xmlTextReaderPtr reader,
}
if (gstyle_utf8_is_spaces (*name))
g_clear_pointer (name, g_free);
gstyle_clear_pointer (name, g_free);
}
return (*id != NULL);
......@@ -144,7 +144,7 @@ gstyle_palette_xml_get_color (xmlTextReaderPtr reader)
{
name = strdup_and_xmlfree (xmlTextReaderGetAttribute (reader, CHAR_TO_XML ("name")));
if (gstyle_utf8_is_spaces (name))
g_clear_pointer (&name, g_free);
gstyle_clear_pointer (&name, g_free);
value = strdup_and_xmlfree (xmlTextReaderGetAttribute (reader, CHAR_TO_XML ("value")));
if (!gstyle_str_empty0 (value))
......@@ -480,7 +480,7 @@ read_gpl_header (GDataInputStream *stream,
{
*palette_name = g_strdup (g_strstrip (&line[5]));
if (gstyle_utf8_is_spaces (*palette_name))
g_clear_pointer (palette_name, g_free);
gstyle_clear_pointer (palette_name, g_free);
g_free (line);
......@@ -1106,11 +1106,11 @@ gstyle_palette_finalize (GObject *object)
{
GstylePalette *self = GSTYLE_PALETTE (object);
g_clear_pointer (&self->colors, g_ptr_array_unref);
g_clear_pointer (&self->color_names, g_hash_table_unref);
g_clear_pointer (&self->name, g_free);
g_clear_pointer (&self->id, g_free);
g_clear_pointer (&self->gettext_domain, g_free);
gstyle_clear_pointer (&self->colors, g_ptr_array_unref);
gstyle_clear_pointer (&self->color_names, g_hash_table_unref);
gstyle_clear_pointer (&self->name, g_free);
gstyle_clear_pointer (&self->id, g_free);
gstyle_clear_pointer (&self->gettext_domain, g_free);
g_clear_object (&self->file);
G_OBJECT_CLASS (gstyle_palette_parent_class)->finalize (object);
......
......@@ -88,4 +88,14 @@ gstyle_utils_cmp_border (GtkBorder border1,
#define gstyle_clear_weak_pointer(ptr) g_clear_weak_pointer(ptr)
#define gstyle_set_weak_pointer(ptr,obj) g_set_weak_pointer(ptr,obj)
/* A more type-correct form of gstyle_clear_pointer(), to help find bugs. */
#define gstyle_clear_pointer(pptr, free_func) \
G_STMT_START { \
G_STATIC_ASSERT (sizeof (*(pptr)) == sizeof (gpointer)); \
typeof(*(pptr)) _dzl_tmp_clear = *(pptr); \
*(pptr) = NULL; \
if (_dzl_tmp_clear) \
free_func (_dzl_tmp_clear); \
} G_STMT_END
G_END_DECLS
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment