[gnome-power-manager] Use g_autoptr() from GLib



commit 1bffd949370d626e38d51c042227b7beb880fdd4
Author: Richard Hughes <richard hughsie com>
Date:   Tue Sep 15 12:24:40 2015 +0100

    Use g_autoptr() from GLib

 configure.ac           |    4 +-
 src/gpm-array-float.c  |   10 +-
 src/gpm-graph-widget.c |  362 +++++++++++++++++++++++++-----------------------
 src/gpm-graph-widget.h |   20 +---
 src/gpm-statistics.c   |  102 +++++---------
 5 files changed, 235 insertions(+), 263 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 25f08db..40db3b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
 AC_PREREQ(2.63)
 
-AC_INIT([gnome-power-manager],[3.17.91])
+AC_INIT([gnome-power-manager],[3.17.92])
 AC_CONFIG_SRCDIR(src)
 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
 AM_INIT_AUTOMAKE([1.11 no-dist-gzip dist-xz tar-ustar foreign])
@@ -68,7 +68,7 @@ GLIB_GSETTINGS
 dnl ---------------------------------------------------------------------------
 dnl - Check library dependencies
 dnl ---------------------------------------------------------------------------
-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.36.0 gobject-2.0 gio-2.0 >= 2.25.9)
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.45.8 gobject-2.0 gio-2.0 >= 2.25.9)
 
 PKG_CHECK_MODULES(GNOME, [
  gtk+-3.0 >= 3.3.8
diff --git a/src/gpm-array-float.c b/src/gpm-array-float.c
index efc728f..960f279 100644
--- a/src/gpm-array-float.c
+++ b/src/gpm-array-float.c
@@ -61,7 +61,7 @@ gpm_array_float_new (guint length)
        array->len = length;
 
        /* clear to 0.0 */
-       for (i=0; i<length; i++)
+       for (i = 0; i < length; i++)
                g_array_index (array, gfloat, i) = 0.0;
        return array;
 }
@@ -118,7 +118,7 @@ gpm_array_float_get_average (GpmArrayFloat *array)
        gfloat average = 0;
 
        length = array->len;
-       for (i=0; i<length; i++)
+       for (i = 0; i < length; i++)
                average += g_array_index (array, gfloat, i);
        return average / (gfloat) length;
 }
@@ -147,7 +147,7 @@ gpm_array_float_compute_gaussian (guint length, gfloat sigma)
 
        /* array positions 0..length, has to be an odd number */
        half_length = (length / 2) + 1;
-       for (i=0; i<half_length; i++) {
+       for (i = 0; i < half_length; i++) {
                division = half_length - (i + 1);
                g_debug ("half_length=%i, div=%f, sigma=%f", half_length, division, sigma);
                g_array_index (array, gfloat, i) = gpm_array_float_guassian_value (division, sigma);
@@ -185,7 +185,7 @@ gpm_array_float_sum (GpmArrayFloat *array)
        gfloat total = 0;
 
        length = array->len;
-       for (i=0; i<length; i++)
+       for (i = 0; i < length; i++)
                total += g_array_index (array, gfloat, i);
        return total;
 }
@@ -205,7 +205,7 @@ gpm_array_float_print (GpmArrayFloat *array)
 
        length = array->len;
        /* debug out */
-       for (i=0; i<length; i++)
+       for (i = 0; i < length; i++)
                g_debug ("[%i]\tval=%f", i, g_array_index (array, gfloat, i));
        return TRUE;
 }
diff --git a/src/gpm-graph-widget.c b/src/gpm-graph-widget.c
index 9cd00dc..e674b6d 100644
--- a/src/gpm-graph-widget.c
+++ b/src/gpm-graph-widget.c
@@ -29,12 +29,9 @@
 #include "gpm-point-obj.h"
 #include "gpm-graph-widget.h"
 
-G_DEFINE_TYPE (GpmGraphWidget, gpm_graph_widget, GTK_TYPE_DRAWING_AREA);
-#define GPM_GRAPH_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_GRAPH_WIDGET, 
GpmGraphWidgetPrivate))
 #define GPM_GRAPH_WIDGET_FONT "Sans 8"
 
-struct GpmGraphWidgetPrivate
-{
+typedef struct {
        gboolean                 use_grid;
        gboolean                 use_legend;
        gboolean                 autorange_x;
@@ -63,7 +60,10 @@ struct GpmGraphWidgetPrivate
 
        GPtrArray               *data_list;
        GPtrArray               *plot_list;
-};
+} GpmGraphWidgetPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GpmGraphWidget, gpm_graph_widget, GTK_TYPE_DRAWING_AREA);
+#define GET_PRIVATE(o) (gpm_graph_widget_get_instance_private (o))
 
 static gboolean gpm_graph_widget_draw (GtkWidget *widget, cairo_t *cr);
 static void    gpm_graph_widget_finalize (GObject *object);
@@ -89,19 +89,20 @@ enum
 static gboolean
 gpm_graph_widget_key_data_clear (GpmGraphWidget *graph)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        GpmGraphWidgetKeyData *keyitem;
        guint i;
 
        g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
 
        /* remove items in list and free */
-       for (i=0; i<g_slist_length (graph->priv->key_data); i++) {
-               keyitem = (GpmGraphWidgetKeyData *) g_slist_nth_data (graph->priv->key_data, i);
+       for (i = 0; i < g_slist_length (priv->key_data); i++) {
+               keyitem = (GpmGraphWidgetKeyData *) g_slist_nth_data (priv->key_data, i);
                g_free (keyitem->desc);
                g_free (keyitem);
        }
-       g_slist_free (graph->priv->key_data);
-       graph->priv->key_data = NULL;
+       g_slist_free (priv->key_data);
+       priv->key_data = NULL;
 
        return TRUE;
 }
@@ -112,6 +113,7 @@ gpm_graph_widget_key_data_clear (GpmGraphWidget *graph)
 gboolean
 gpm_graph_widget_key_data_add (GpmGraphWidget *graph, guint32 color, const gchar *desc)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        GpmGraphWidgetKeyData *keyitem;
 
        g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
@@ -122,7 +124,7 @@ gpm_graph_widget_key_data_add (GpmGraphWidget *graph, guint32 color, const gchar
        keyitem->color = color;
        keyitem->desc = g_strdup (desc);
 
-       graph->priv->key_data = g_slist_append (graph->priv->key_data, (gpointer) keyitem);
+       priv->key_data = g_slist_append (priv->key_data, (gpointer) keyitem);
        return TRUE;
 }
 
@@ -133,36 +135,37 @@ static void
 up_graph_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 {
        GpmGraphWidget *graph = GPM_GRAPH_WIDGET (object);
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        switch (prop_id) {
        case PROP_USE_LEGEND:
-               g_value_set_boolean (value, graph->priv->use_legend);
+               g_value_set_boolean (value, priv->use_legend);
                break;
        case PROP_USE_GRID:
-               g_value_set_boolean (value, graph->priv->use_grid);
+               g_value_set_boolean (value, priv->use_grid);
                break;
        case PROP_TYPE_X:
-               g_value_set_uint (value, graph->priv->type_x);
+               g_value_set_uint (value, priv->type_x);
                break;
        case PROP_TYPE_Y:
-               g_value_set_uint (value, graph->priv->type_y);
+               g_value_set_uint (value, priv->type_y);
                break;
        case PROP_AUTORANGE_X:
-               g_value_set_boolean (value, graph->priv->autorange_x);
+               g_value_set_boolean (value, priv->autorange_x);
                break;
        case PROP_AUTORANGE_Y:
-               g_value_set_boolean (value, graph->priv->autorange_y);
+               g_value_set_boolean (value, priv->autorange_y);
                break;
        case PROP_START_X:
-               g_value_set_int (value, graph->priv->start_x);
+               g_value_set_int (value, priv->start_x);
                break;
        case PROP_START_Y:
-               g_value_set_int (value, graph->priv->start_y);
+               g_value_set_int (value, priv->start_y);
                break;
        case PROP_STOP_X:
-               g_value_set_int (value, graph->priv->stop_x);
+               g_value_set_int (value, priv->stop_x);
                break;
        case PROP_STOP_Y:
-               g_value_set_int (value, graph->priv->stop_y);
+               g_value_set_int (value, priv->stop_y);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -177,37 +180,38 @@ static void
 up_graph_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 {
        GpmGraphWidget *graph = GPM_GRAPH_WIDGET (object);
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
 
        switch (prop_id) {
        case PROP_USE_LEGEND:
-               graph->priv->use_legend = g_value_get_boolean (value);
+               priv->use_legend = g_value_get_boolean (value);
                break;
        case PROP_USE_GRID:
-               graph->priv->use_grid = g_value_get_boolean (value);
+               priv->use_grid = g_value_get_boolean (value);
                break;
        case PROP_TYPE_X:
-               graph->priv->type_x = g_value_get_uint (value);
+               priv->type_x = g_value_get_uint (value);
                break;
        case PROP_TYPE_Y:
-               graph->priv->type_y = g_value_get_uint (value);
+               priv->type_y = g_value_get_uint (value);
                break;
        case PROP_AUTORANGE_X:
-               graph->priv->autorange_x = g_value_get_boolean (value);
+               priv->autorange_x = g_value_get_boolean (value);
                break;
        case PROP_AUTORANGE_Y:
-               graph->priv->autorange_y = g_value_get_boolean (value);
+               priv->autorange_y = g_value_get_boolean (value);
                break;
        case PROP_START_X:
-               graph->priv->start_x = g_value_get_int (value);
+               priv->start_x = g_value_get_int (value);
                break;
        case PROP_START_Y:
-               graph->priv->start_y = g_value_get_int (value);
+               priv->start_y = g_value_get_int (value);
                break;
        case PROP_STOP_X:
-               graph->priv->stop_x = g_value_get_int (value);
+               priv->stop_x = g_value_get_int (value);
                break;
        case PROP_STOP_Y:
-               graph->priv->stop_y = g_value_get_int (value);
+               priv->stop_y = g_value_get_int (value);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -234,8 +238,6 @@ gpm_graph_widget_class_init (GpmGraphWidgetClass *class)
        object_class->set_property = up_graph_set_property;
        object_class->finalize = gpm_graph_widget_finalize;
 
-       g_type_class_add_private (class, sizeof (GpmGraphWidgetPrivate));
-
        /* properties */
        g_object_class_install_property (object_class,
                                         PROP_USE_LEGEND,
@@ -302,27 +304,27 @@ gpm_graph_widget_init (GpmGraphWidget *graph)
 {
        PangoContext *context;
        PangoFontDescription *desc;
-
-       graph->priv = GPM_GRAPH_WIDGET_GET_PRIVATE (graph);
-       graph->priv->start_x = 0;
-       graph->priv->start_y = 0;
-       graph->priv->stop_x = 60;
-       graph->priv->stop_y = 100;
-       graph->priv->use_grid = TRUE;
-       graph->priv->use_legend = FALSE;
-       graph->priv->data_list = g_ptr_array_new_with_free_func ((GDestroyNotify) g_ptr_array_unref);
-       graph->priv->plot_list = g_ptr_array_new ();
-       graph->priv->key_data = NULL;
-       graph->priv->type_x = GPM_GRAPH_WIDGET_TYPE_TIME;
-       graph->priv->type_y = GPM_GRAPH_WIDGET_TYPE_PERCENTAGE;
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+
+       priv->start_x = 0;
+       priv->start_y = 0;
+       priv->stop_x = 60;
+       priv->stop_y = 100;
+       priv->use_grid = TRUE;
+       priv->use_legend = FALSE;
+       priv->data_list = g_ptr_array_new_with_free_func ((GDestroyNotify) g_ptr_array_unref);
+       priv->plot_list = g_ptr_array_new ();
+       priv->key_data = NULL;
+       priv->type_x = GPM_GRAPH_WIDGET_TYPE_TIME;
+       priv->type_y = GPM_GRAPH_WIDGET_TYPE_PERCENTAGE;
 
        /* do pango stuff */
        context = gtk_widget_get_pango_context (GTK_WIDGET (graph));
        pango_context_set_base_gravity (context, PANGO_GRAVITY_AUTO);
 
-       graph->priv->layout = pango_layout_new (context);
+       priv->layout = pango_layout_new (context);
        desc = pango_font_description_from_string (GPM_GRAPH_WIDGET_FONT);
-       pango_layout_set_font_description (graph->priv->layout, desc);
+       pango_layout_set_font_description (priv->layout, desc);
        pango_font_description_free (desc);
 }
 
@@ -332,10 +334,12 @@ gpm_graph_widget_init (GpmGraphWidget *graph)
 gboolean
 gpm_graph_widget_data_clear (GpmGraphWidget *graph)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+
        g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
 
-       g_ptr_array_set_size (graph->priv->data_list, 0);
-       g_ptr_array_set_size (graph->priv->plot_list, 0);
+       g_ptr_array_set_size (priv->data_list, 0);
+       g_ptr_array_set_size (priv->plot_list, 0);
 
        return TRUE;
 }
@@ -348,16 +352,17 @@ static void
 gpm_graph_widget_finalize (GObject *object)
 {
        GpmGraphWidget *graph = (GpmGraphWidget*) object;
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
 
        /* clear key and data */
        gpm_graph_widget_key_data_clear (graph);
        gpm_graph_widget_data_clear (graph);
 
        /* free data */
-       g_ptr_array_unref (graph->priv->data_list);
-       g_ptr_array_unref (graph->priv->plot_list);
+       g_ptr_array_unref (priv->data_list);
+       g_ptr_array_unref (priv->plot_list);
 
-       g_object_unref (graph->priv->layout);
+       g_object_unref (priv->layout);
 
        G_OBJECT_CLASS (gpm_graph_widget_parent_class)->finalize (object);
 }
@@ -372,6 +377,7 @@ gpm_graph_widget_finalize (GObject *object)
 gboolean
 gpm_graph_widget_data_assign (GpmGraphWidget *graph, GpmGraphWidgetPlot plot, GPtrArray *data)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        GPtrArray *copy;
        GpmPointObj *obj;
        guint i;
@@ -381,14 +387,14 @@ gpm_graph_widget_data_assign (GpmGraphWidget *graph, GpmGraphWidgetPlot plot, GP
 
        /* make a deep copy */
        copy = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
-       for (i=0; i<data->len; i++) {
+       for (i = 0; i < data->len; i++) {
                obj = gpm_point_obj_copy (g_ptr_array_index (data, i));
                g_ptr_array_add (copy, obj);
        }
 
        /* get the new data */
-       g_ptr_array_add (graph->priv->data_list, copy);
-       g_ptr_array_add (graph->priv->plot_list, GUINT_TO_POINTER(plot));
+       g_ptr_array_add (priv->data_list, copy);
+       g_ptr_array_add (priv->plot_list, GUINT_TO_POINTER(plot));
 
        /* refresh */
        gtk_widget_queue_draw (GTK_WIDGET (graph));
@@ -475,11 +481,12 @@ gpm_get_axis_label (GpmGraphWidgetType axis, gfloat value)
 static void
 gpm_graph_widget_draw_grid (GpmGraphWidget *graph, cairo_t *cr)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        guint i;
        gfloat b;
        gdouble dotted[] = {1., 2.};
-       gfloat divwidth  = (gfloat)graph->priv->box_width / 10.0f;
-       gfloat divheight = (gfloat)graph->priv->box_height / 10.0f;
+       gfloat divwidth  = (gfloat)priv->box_width / 10.0f;
+       gfloat divheight = (gfloat)priv->box_height / 10.0f;
 
        cairo_save (cr);
 
@@ -489,17 +496,17 @@ gpm_graph_widget_draw_grid (GpmGraphWidget *graph, cairo_t *cr)
        /* do vertical lines */
        cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
        for (i=1; i<10; i++) {
-               b = graph->priv->box_x + ((gfloat) i * divwidth);
-               cairo_move_to (cr, (gint)b + 0.5f, graph->priv->box_y);
-               cairo_line_to (cr, (gint)b + 0.5f, graph->priv->box_y + graph->priv->box_height);
+               b = priv->box_x + ((gfloat) i * divwidth);
+               cairo_move_to (cr, (gint)b + 0.5f, priv->box_y);
+               cairo_line_to (cr, (gint)b + 0.5f, priv->box_y + priv->box_height);
                cairo_stroke (cr);
        }
 
        /* do horizontal lines */
        for (i=1; i<10; i++) {
-               b = graph->priv->box_y + ((gfloat) i * divheight);
-               cairo_move_to (cr, graph->priv->box_x, (gint)b + 0.5f);
-               cairo_line_to (cr, graph->priv->box_x + graph->priv->box_width, (int)b + 0.5f);
+               b = priv->box_y + ((gfloat) i * divheight);
+               cairo_move_to (cr, priv->box_x, (gint)b + 0.5f);
+               cairo_line_to (cr, priv->box_x + priv->box_width, (int)b + 0.5f);
                cairo_stroke (cr);
        }
 
@@ -516,14 +523,14 @@ gpm_graph_widget_draw_grid (GpmGraphWidget *graph, cairo_t *cr)
 static void
 gpm_graph_widget_draw_labels (GpmGraphWidget *graph, cairo_t *cr)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        guint i;
        gfloat b;
-       gchar *text;
        gfloat value;
-       gfloat divwidth  = (gfloat)graph->priv->box_width / 10.0f;
-       gfloat divheight = (gfloat)graph->priv->box_height / 10.0f;
-       gint length_x = graph->priv->stop_x - graph->priv->start_x;
-       gint length_y = graph->priv->stop_y - graph->priv->start_y;
+       gfloat divwidth  = (gfloat)priv->box_width / 10.0f;
+       gfloat divheight = (gfloat)priv->box_height / 10.0f;
+       gint length_x = priv->stop_x - priv->start_x;
+       gint length_y = priv->stop_y - priv->start_y;
        PangoRectangle ink_rect, logical_rect;
        gfloat offsetx = 0;
        gfloat offsety = 0;
@@ -532,13 +539,14 @@ gpm_graph_widget_draw_labels (GpmGraphWidget *graph, cairo_t *cr)
 
        /* do x text */
        cairo_set_source_rgb (cr, 0, 0, 0);
-       for (i=0; i<11; i++) {
-               b = graph->priv->box_x + ((gfloat) i * divwidth);
-               value = ((length_x / 10.0f) * (gfloat) i) + (gfloat) graph->priv->start_x;
-               text = gpm_get_axis_label (graph->priv->type_x, value);
-
-               pango_layout_set_text (graph->priv->layout, text, -1);
-               pango_layout_get_pixel_extents (graph->priv->layout, &ink_rect, &logical_rect);
+       for (i = 0; i < 11; i++) {
+               g_autofree gchar *text = NULL;
+               b = priv->box_x + ((gfloat) i * divwidth);
+               value = ((length_x / 10.0f) * (gfloat) i) + (gfloat) priv->start_x;
+               text = gpm_get_axis_label (priv->type_x, value);
+
+               pango_layout_set_text (priv->layout, text, -1);
+               pango_layout_get_pixel_extents (priv->layout, &ink_rect, &logical_rect);
                /* have data points 0 and 10 bounded, but 1..9 centered */
                if (i == 0)
                        offsetx = 2.0;
@@ -548,20 +556,20 @@ gpm_graph_widget_draw_labels (GpmGraphWidget *graph, cairo_t *cr)
                        offsetx = (ink_rect.width / 2.0f);
 
                cairo_move_to (cr, b - offsetx,
-                              graph->priv->box_y + graph->priv->box_height + 2.0);
+                              priv->box_y + priv->box_height + 2.0);
 
-               pango_cairo_show_layout (cr, graph->priv->layout);
-               g_free (text);
+               pango_cairo_show_layout (cr, priv->layout);
        }
 
        /* do y text */
-       for (i=0; i<11; i++) {
-               b = graph->priv->box_y + ((gfloat) i * divheight);
-               value = ((gfloat) length_y / 10.0f) * (10 - (gfloat) i) + graph->priv->start_y;
-               text = gpm_get_axis_label (graph->priv->type_y, value);
+       for (i = 0; i < 11; i++) {
+               g_autofree gchar *text = NULL;
+               b = priv->box_y + ((gfloat) i * divheight);
+               value = ((gfloat) length_y / 10.0f) * (10 - (gfloat) i) + priv->start_y;
+               text = gpm_get_axis_label (priv->type_y, value);
 
-               pango_layout_set_text (graph->priv->layout, text, -1);
-               pango_layout_get_pixel_extents (graph->priv->layout, &ink_rect, &logical_rect);
+               pango_layout_set_text (priv->layout, text, -1);
+               pango_layout_get_pixel_extents (priv->layout, &ink_rect, &logical_rect);
 
                /* have data points 0 and 10 bounded, but 1..9 centered */
                if (i == 10)
@@ -572,9 +580,8 @@ gpm_graph_widget_draw_labels (GpmGraphWidget *graph, cairo_t *cr)
                        offsety = (ink_rect.height / 2.0f);
                offsetx = ink_rect.width + 7;
                offsety -= 10;
-               cairo_move_to (cr, graph->priv->box_x - offsetx - 2, b + offsety);
-               pango_cairo_show_layout (cr, graph->priv->layout);
-               g_free (text);
+               cairo_move_to (cr, priv->box_x - offsetx - 2, b + offsety);
+               pango_cairo_show_layout (cr, priv->layout);
        }
 
        cairo_restore (cr);
@@ -604,22 +611,22 @@ gpm_color_to_rgb (guint32 color, guint8 *red, guint8 *green, guint8 *blue)
 static guint
 gpm_graph_widget_get_y_label_max_width (GpmGraphWidget *graph, cairo_t *cr)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        guint i;
-       gchar *text;
        gint value;
-       gint length_y = graph->priv->stop_y - graph->priv->start_y;
+       gint length_y = priv->stop_y - priv->start_y;
        PangoRectangle ink_rect, logical_rect;
        guint biggest = 0;
 
        /* do y text */
-       for (i=0; i<11; i++) {
-               value = (length_y / 10) * (10 - (gfloat) i) + graph->priv->start_y;
-               text = gpm_get_axis_label (graph->priv->type_y, value);
-               pango_layout_set_text (graph->priv->layout, text, -1);
-               pango_layout_get_pixel_extents (graph->priv->layout, &ink_rect, &logical_rect);
+       for (i = 0; i < 11; i++) {
+               g_autofree gchar *text = NULL;
+               value = (length_y / 10) * (10 - (gfloat) i) + priv->start_y;
+               text = gpm_get_axis_label (priv->type_y, value);
+               pango_layout_set_text (priv->layout, text, -1);
+               pango_layout_get_pixel_extents (priv->layout, &ink_rect, &logical_rect);
                if (ink_rect.width > (gint) biggest)
                        biggest = ink_rect.width;
-               g_free (text);
        }
        return biggest;
 }
@@ -689,6 +696,7 @@ gpm_round_down (gfloat value, gint smallest)
 static void
 gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        gfloat biggest_x = G_MINFLOAT;
        gfloat smallest_x = G_MAXFLOAT;
        guint rounding_x = 1;
@@ -698,7 +706,7 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
        guint len = 0;
        GPtrArray *array;
 
-       array = graph->priv->data_list;
+       array = priv->data_list;
 
        /* find out if we have no data */
        for (j=0; j<array->len; j++) {
@@ -711,8 +719,8 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
        /* no data in any array */
        if (len == 0) {
                g_debug ("no data");
-               graph->priv->start_x = 0;
-               graph->priv->stop_x = 10;
+               priv->start_x = 0;
+               priv->stop_x = 10;
                return;
        }
 
@@ -734,15 +742,15 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
                smallest_x--;
        }
 
-       if (graph->priv->type_x == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
+       if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
                rounding_x = 10;
-       } else if (graph->priv->type_x == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
+       } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
                rounding_x = 1;
-       } else if (graph->priv->type_x == GPM_GRAPH_WIDGET_TYPE_POWER) {
+       } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_POWER) {
                rounding_x = 10;
-       } else if (graph->priv->type_x == GPM_GRAPH_WIDGET_TYPE_VOLTAGE) {
+       } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_VOLTAGE) {
                rounding_x = 1000;
-       } else if (graph->priv->type_x == GPM_GRAPH_WIDGET_TYPE_TIME) {
+       } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_TIME) {
                if (biggest_x-smallest_x < 150)
                        rounding_x = 150;
                else if (biggest_x-smallest_x < 5*60)
@@ -751,25 +759,25 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
                        rounding_x = 10 * 60;
        }
 
-       graph->priv->start_x = gpm_round_down (smallest_x, rounding_x);
-       graph->priv->stop_x = gpm_round_up (biggest_x, rounding_x);
+       priv->start_x = gpm_round_down (smallest_x, rounding_x);
+       priv->stop_x = gpm_round_up (biggest_x, rounding_x);
 
        g_debug ("Processed(1) range is %i<x<%i",
-                  graph->priv->start_x, graph->priv->stop_x);
+                  priv->start_x, priv->stop_x);
 
        /* if percentage, and close to the end points, then extend */
-       if (graph->priv->type_x == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
-               if (graph->priv->stop_x >= 90)
-                       graph->priv->stop_x = 100;
-               if (graph->priv->start_x > 0 && graph->priv->start_x <= 10)
-                       graph->priv->start_x = 0;
-       } else if (graph->priv->type_x == GPM_GRAPH_WIDGET_TYPE_TIME) {
-               if (graph->priv->start_x > 0 && graph->priv->start_x <= 60*10)
-                       graph->priv->start_x = 0;
+       if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
+               if (priv->stop_x >= 90)
+                       priv->stop_x = 100;
+               if (priv->start_x > 0 && priv->start_x <= 10)
+                       priv->start_x = 0;
+       } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_TIME) {
+               if (priv->start_x > 0 && priv->start_x <= 60*10)
+                       priv->start_x = 0;
        }
 
        g_debug ("Processed range is %i<x<%i",
-                  graph->priv->start_x, graph->priv->stop_x);
+                  priv->start_x, priv->stop_x);
 }
 
 /**
@@ -783,6 +791,7 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
 static void
 gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        gfloat biggest_y = G_MINFLOAT;
        gfloat smallest_y = G_MAXFLOAT;
        guint rounding_y = 1;
@@ -792,7 +801,7 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
        guint len = 0;
        GPtrArray *array;
 
-       array = graph->priv->data_list;
+       array = priv->data_list;
 
        /* find out if we have no data */
        for (j=0; j<array->len; j++) {
@@ -805,8 +814,8 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
        /* no data in any array */
        if (len == 0) {
                g_debug ("no data");
-               graph->priv->start_y = 0;
-               graph->priv->stop_y = 10;
+               priv->start_y = 0;
+               priv->stop_y = 10;
                return;
        }
 
@@ -828,15 +837,15 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
                smallest_y--;
        }
 
-       if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
+       if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
                rounding_y = 10;
-       } else if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
+       } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
                rounding_y = 1;
-       } else if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_POWER) {
+       } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_POWER) {
                rounding_y = 10;
-       } else if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_VOLTAGE) {
+       } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_VOLTAGE) {
                rounding_y = 1000;
-       } else if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_TIME) {
+       } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_TIME) {
                if (biggest_y-smallest_y < 150)
                        rounding_y = 150;
                else if (biggest_y < 5*60)
@@ -845,32 +854,32 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
                        rounding_y = 10 * 60;
        }
 
-       graph->priv->start_y = gpm_round_down (smallest_y, rounding_y);
-       graph->priv->stop_y = gpm_round_up (biggest_y, rounding_y);
+       priv->start_y = gpm_round_down (smallest_y, rounding_y);
+       priv->stop_y = gpm_round_up (biggest_y, rounding_y);
 
        /* a factor graph always is centered around zero */
-       if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
-               if (abs (graph->priv->stop_y) > abs (graph->priv->start_y))
-                       graph->priv->start_y = -graph->priv->stop_y;
+       if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
+               if (abs (priv->stop_y) > abs (priv->start_y))
+                       priv->start_y = -priv->stop_y;
                else
-                       graph->priv->stop_y = -graph->priv->start_y;
+                       priv->stop_y = -priv->start_y;
        }
 
        g_debug ("Processed(1) range is %i<y<%i",
-                  graph->priv->start_y, graph->priv->stop_y);
-
-       if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
-               if (graph->priv->stop_y >= 90)
-                       graph->priv->stop_y = 100;
-               if (graph->priv->start_y > 0 && graph->priv->start_y <= 10)
-                       graph->priv->start_y = 0;
-       } else if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_TIME) {
-               if (graph->priv->start_y <= 60*10)
-                       graph->priv->start_y = 0;
+                  priv->start_y, priv->stop_y);
+
+       if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
+               if (priv->stop_y >= 90)
+                       priv->stop_y = 100;
+               if (priv->start_y > 0 && priv->start_y <= 10)
+                       priv->start_y = 0;
+       } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_TIME) {
+               if (priv->start_y <= 60*10)
+                       priv->start_y = 0;
        }
 
        g_debug ("Processed range is %i<y<%i",
-                  graph->priv->start_y, graph->priv->stop_y);
+                  priv->start_y, priv->stop_y);
 }
 
 /**
@@ -922,8 +931,9 @@ gpm_graph_widget_draw_legend_line (cairo_t *cr, gfloat x, gfloat y, guint32 colo
 static void
 gpm_graph_widget_get_pos_on_graph (GpmGraphWidget *graph, gfloat data_x, gfloat data_y, float *x, float *y)
 {
-       *x = graph->priv->box_x + (graph->priv->unit_x * (data_x - graph->priv->start_x)) + 1;
-       *y = graph->priv->box_y + (graph->priv->unit_y * (gfloat)(graph->priv->stop_y - data_y)) + 1.5;
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+       *x = priv->box_x + (priv->unit_x * (data_x - priv->start_x)) + 1;
+       *y = priv->box_y + (priv->unit_y * (gfloat)(priv->stop_y - data_y)) + 1.5;
 }
 
 /**
@@ -955,6 +965,7 @@ gpm_graph_widget_draw_dot (cairo_t *cr, gfloat x, gfloat y, guint32 color)
 static void
 gpm_graph_widget_draw_line (GpmGraphWidget *graph, cairo_t *cr)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        gfloat oldx, oldy;
        gfloat newx, newy;
        GPtrArray *data;
@@ -963,20 +974,20 @@ gpm_graph_widget_draw_line (GpmGraphWidget *graph, cairo_t *cr)
        GpmPointObj *point;
        guint i, j;
 
-       if (graph->priv->data_list->len == 0) {
+       if (priv->data_list->len == 0) {
                g_debug ("no data");
                return;
        }
        cairo_save (cr);
 
-       array = graph->priv->data_list;
+       array = priv->data_list;
 
        /* do each line */
        for (j=0; j<array->len; j++) {
                data = g_ptr_array_index (array, j);
                if (data->len == 0)
                        continue;
-               plot = GPOINTER_TO_UINT (g_ptr_array_index (graph->priv->plot_list, j));
+               plot = GPOINTER_TO_UINT (g_ptr_array_index (priv->plot_list, j));
 
                /* get the very first point so we can work out the old */
                point = (GpmPointObj *) g_ptr_array_index (data, 0);
@@ -1053,7 +1064,8 @@ gpm_graph_widget_draw_bounding_box (cairo_t *cr, gint x, gint y, gint width, gin
 static void
 gpm_graph_widget_draw_legend (GpmGraphWidget *graph, gint x, gint y, gint width, gint height)
 {
-       cairo_t *cr = graph->priv->cr;
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+       cairo_t *cr = priv->cr;
        gint y_count;
        guint i;
        GpmGraphWidgetKeyData *keydataitem;
@@ -1062,8 +1074,8 @@ gpm_graph_widget_draw_legend (GpmGraphWidget *graph, gint x, gint y, gint width,
        y_count = y + 10;
 
        /* add the line colors to the legend */
-       for (i=0; i<g_slist_length (graph->priv->key_data); i++) {
-               keydataitem = (GpmGraphWidgetKeyData *) g_slist_nth_data (graph->priv->key_data, i);
+       for (i = 0; i < g_slist_length (priv->key_data); i++) {
+               keydataitem = (GpmGraphWidgetKeyData *) g_slist_nth_data (priv->key_data, i);
                if (keydataitem == NULL) {
                        /* this shouldn't ever happen */
                        g_warning ("keydataitem NULL!");
@@ -1072,8 +1084,8 @@ gpm_graph_widget_draw_legend (GpmGraphWidget *graph, gint x, gint y, gint width,
                gpm_graph_widget_draw_legend_line (cr, x + 8, y_count, keydataitem->color);
                cairo_move_to (cr, x + 8 + 10, y_count - 6);
                cairo_set_source_rgb (cr, 0, 0, 0);
-               pango_layout_set_text (graph->priv->layout, keydataitem->desc, -1);
-               pango_cairo_show_layout (cr, graph->priv->layout);
+               pango_layout_set_text (priv->layout, keydataitem->desc, -1);
+               pango_cairo_show_layout (cr, priv->layout);
                y_count = y_count + GPM_GRAPH_WIDGET_LEGEND_SPACING;
        }
 }
@@ -1092,6 +1104,7 @@ static gboolean
 gpm_graph_widget_legend_calculate_size (GpmGraphWidget *graph, cairo_t *cr,
                                        guint *width, guint *height)
 {
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        guint i;
        PangoRectangle ink_rect, logical_rect;
        GpmGraphWidgetKeyData *keydataitem;
@@ -1103,11 +1116,11 @@ gpm_graph_widget_legend_calculate_size (GpmGraphWidget *graph, cairo_t *cr,
        *height = 0;
 
        /* add the line colors to the legend */
-       for (i=0; i<g_slist_length (graph->priv->key_data); i++) {
-               keydataitem = (GpmGraphWidgetKeyData *) g_slist_nth_data (graph->priv->key_data, i);
+       for (i = 0; i < g_slist_length (priv->key_data); i++) {
+               keydataitem = (GpmGraphWidgetKeyData *) g_slist_nth_data (priv->key_data, i);
                *height = *height + GPM_GRAPH_WIDGET_LEGEND_SPACING;
-               pango_layout_set_text (graph->priv->layout, keydataitem->desc, -1);
-               pango_layout_get_pixel_extents (graph->priv->layout, &ink_rect, &logical_rect);
+               pango_layout_set_text (priv->layout, keydataitem->desc, -1);
+               pango_layout_get_pixel_extents (priv->layout, &ink_rect, &logical_rect);
                if ((gint) *width < ink_rect.width)
                        *width = ink_rect.width;
        }
@@ -1142,6 +1155,7 @@ gpm_graph_widget_draw (GtkWidget *widget, cairo_t *cr)
        gfloat data_y;
 
        GpmGraphWidget *graph = (GpmGraphWidget*) widget;
+       GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
        g_return_val_if_fail (graph != NULL, FALSE);
        g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
 
@@ -1149,44 +1163,44 @@ gpm_graph_widget_draw (GtkWidget *widget, cairo_t *cr)
        cairo_save (cr);
 
        /* we need this so we know the y text */
-       if (graph->priv->autorange_x)
+       if (priv->autorange_x)
                gpm_graph_widget_autorange_x (graph);
-       if (graph->priv->autorange_y)
+       if (priv->autorange_y)
                gpm_graph_widget_autorange_y (graph);
 
-       graph->priv->box_x = gpm_graph_widget_get_y_label_max_width (graph, cr) + 10;
-       graph->priv->box_y = 5;
+       priv->box_x = gpm_graph_widget_get_y_label_max_width (graph, cr) + 10;
+       priv->box_y = 5;
 
        gtk_widget_get_allocation (widget, &allocation);
-       graph->priv->box_height = allocation.height - (20 + graph->priv->box_y);
+       priv->box_height = allocation.height - (20 + priv->box_y);
 
        /* make size adjustment for legend */
-       if (graph->priv->use_legend && legend_height > 0) {
-               graph->priv->box_width = allocation.width -
-                                        (3 + legend_width + 5 + graph->priv->box_x);
-               legend_x = graph->priv->box_x + graph->priv->box_width + 6;
-               legend_y = graph->priv->box_y;
+       if (priv->use_legend && legend_height > 0) {
+               priv->box_width = allocation.width -
+                                        (3 + legend_width + 5 + priv->box_x);
+               legend_x = priv->box_x + priv->box_width + 6;
+               legend_y = priv->box_y;
        } else {
-               graph->priv->box_width = allocation.width -
-                                        (3 + graph->priv->box_x);
+               priv->box_width = allocation.width -
+                                        (3 + priv->box_x);
        }
 
        /* graph background */
-       gpm_graph_widget_draw_bounding_box (cr, graph->priv->box_x, graph->priv->box_y,
-                                    graph->priv->box_width, graph->priv->box_height);
-       if (graph->priv->use_grid)
+       gpm_graph_widget_draw_bounding_box (cr, priv->box_x, priv->box_y,
+                                    priv->box_width, priv->box_height);
+       if (priv->use_grid)
                gpm_graph_widget_draw_grid (graph, cr);
 
        /* -3 is so we can keep the lines inside the box at both extremes */
-       data_x = graph->priv->stop_x - graph->priv->start_x;
-       data_y = graph->priv->stop_y - graph->priv->start_y;
-       graph->priv->unit_x = (float)(graph->priv->box_width - 3) / (float) data_x;
-       graph->priv->unit_y = (float)(graph->priv->box_height - 3) / (float) data_y;
+       data_x = priv->stop_x - priv->start_x;
+       data_y = priv->stop_y - priv->start_y;
+       priv->unit_x = (float)(priv->box_width - 3) / (float) data_x;
+       priv->unit_y = (float)(priv->box_height - 3) / (float) data_y;
 
        gpm_graph_widget_draw_labels (graph, cr);
        gpm_graph_widget_draw_line (graph, cr);
 
-       if (graph->priv->use_legend && legend_height > 0)
+       if (priv->use_legend && legend_height > 0)
                gpm_graph_widget_draw_legend (graph, legend_x, legend_y, legend_width, legend_height);
 
        cairo_restore (cr);
diff --git a/src/gpm-graph-widget.h b/src/gpm-graph-widget.h
index d9c127f..f6cf04d 100644
--- a/src/gpm-graph-widget.h
+++ b/src/gpm-graph-widget.h
@@ -27,19 +27,11 @@
 
 G_BEGIN_DECLS
 
-#define GPM_TYPE_GRAPH_WIDGET          (gpm_graph_widget_get_type ())
-#define GPM_GRAPH_WIDGET(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), GPM_TYPE_GRAPH_WIDGET, 
GpmGraphWidget))
-#define GPM_GRAPH_WIDGET_CLASS(obj)    (G_TYPE_CHECK_CLASS_CAST ((obj), GPM_GRAPH_WIDGET, 
GpmGraphWidgetClass))
-#define GPM_IS_GRAPH_WIDGET(obj)       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GPM_TYPE_GRAPH_WIDGET))
-#define GPM_IS_GRAPH_WIDGET_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), EFF_TYPE_GRAPH_WIDGET))
-#define GPM_GRAPH_WIDGET_GET_CLASS     (G_TYPE_INSTANCE_GET_CLASS ((obj), GPM_TYPE_GRAPH_WIDGET, 
GpmGraphWidgetClass))
+#define GPM_TYPE_GRAPH_WIDGET (gpm_graph_widget_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GpmGraphWidget, gpm_graph_widget, GPM, GRAPH_WIDGET, GtkDrawingArea)
 
 #define GPM_GRAPH_WIDGET_LEGEND_SPACING                17
 
-typedef struct GpmGraphWidget          GpmGraphWidget;
-typedef struct GpmGraphWidgetClass     GpmGraphWidgetClass;
-typedef struct GpmGraphWidgetPrivate   GpmGraphWidgetPrivate;
-
 typedef enum {
        GPM_GRAPH_WIDGET_TYPE_INVALID,
        GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
@@ -62,13 +54,7 @@ typedef struct {
        gchar                   *desc;
 } GpmGraphWidgetKeyData;
 
-struct GpmGraphWidget
-{
-       GtkDrawingArea           parent;
-       GpmGraphWidgetPrivate   *priv;
-};
-
-struct GpmGraphWidgetClass
+struct _GpmGraphWidgetClass
 {
        GtkDrawingAreaClass parent_class;
 };
diff --git a/src/gpm-statistics.c b/src/gpm-statistics.c
index b6cf3c5..367399c 100644
--- a/src/gpm-statistics.c
+++ b/src/gpm-statistics.c
@@ -145,14 +145,14 @@ gpm_stats_get_device_icon_suffix (UpDevice *device)
 static GIcon *
 gpm_stats_get_device_icon (UpDevice *device, gboolean use_symbolic)
 {
-       GString *filename;
-       gchar **iconnames;
        const gchar *suffix_str;
        UpDeviceKind kind;
        UpDeviceState state;
        gboolean is_present;
        gdouble percentage;
        GIcon *icon = NULL;
+       g_auto(GStrv) iconnames;
+       g_autoptr(GString) filename;
 
        g_return_val_if_fail (device != NULL, NULL);
 
@@ -231,9 +231,6 @@ gpm_stats_get_device_icon (UpDevice *device, gboolean use_symbolic)
 
        iconnames = g_strsplit (filename->str, ";", -1);
        icon = g_themed_icon_new_from_names (iconnames, -1);
-
-       g_strfreev (iconnames);
-       g_string_free (filename, TRUE);
        return icon;
 }
 
@@ -508,7 +505,7 @@ gpm_stats_update_smooth_data (GPtrArray *list)
 
        /* convert the y data to a GpmArrayFloat array */
        raw = gpm_array_float_new (list->len);
-       for (i=0; i<list->len; i++) {
+       for (i = 0; i < list->len; i++) {
                point = (GpmPointObj *) g_ptr_array_index (list, i);
                gpm_array_float_set (raw, i, point->y);
        }
@@ -522,7 +519,7 @@ gpm_stats_update_smooth_data (GPtrArray *list)
 
        /* add the smoothed data back into a new array */
        new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
-       for (i=0; i<list->len; i++) {
+       for (i = 0; i < list->len; i++) {
                point = (GpmPointObj *) g_ptr_array_index (list, i);
                point_new = g_new0 (GpmPointObj, 1);
                point_new->color = point->color;
@@ -626,10 +623,10 @@ gpm_stats_update_info_page_details (UpDevice *device)
        guint64 update_time;
        gint64 time_to_full;
        gint64 time_to_empty;
-       gchar *vendor = NULL;
-       gchar *serial = NULL;
-       gchar *model = NULL;
-       gchar *device_path = NULL;
+       g_autofree gchar *device_path = NULL;
+       g_autofree gchar *model = NULL;
+       g_autofree gchar *serial = NULL;
+       g_autofree gchar *vendor = NULL;
 
        gtk_list_store_clear (list_store_info);
 
@@ -667,7 +664,6 @@ gpm_stats_update_info_page_details (UpDevice *device)
        device_path = gpm_stats_get_printable_device_path (device);
        /* TRANSLATORS: the device ID of the current device, e.g. "battery0" */
        gpm_stats_add_info_data (_("Device"), device_path);
-       g_free (device_path);
 
        gpm_stats_add_info_data (_("Type"), gpm_device_kind_to_localised_string (kind, 1));
        if (vendor != NULL && vendor[0] != '\0')
@@ -778,10 +774,6 @@ gpm_stats_update_info_page_details (UpDevice *device)
                 * only shown for the ac adaptor device */
                gpm_stats_add_info_data (_("Online"), gpm_stats_bool_to_string (online));
        }
-
-       g_free (vendor);
-       g_free (serial);
-       g_free (model);
 }
 
 /**
@@ -893,7 +885,7 @@ gpm_stats_update_info_page_history (UpDevice *device)
        g_get_current_time (&timeval);
        offset = timeval.tv_sec;
 
-       for (i=0; i<array->len; i++) {
+       for (i = 0; i < array->len; i++) {
                item = (UpHistoryItem *) g_ptr_array_index (array, i);
 
                /* abandon this point */
@@ -999,7 +991,7 @@ gpm_stats_update_info_page_stats (UpDevice *device)
        gtk_widget_hide (widget);
        gtk_widget_show (graph_statistics);
 
-       for (i=0; i<array->len; i++) {
+       for (i = 0; i < array->len; i++) {
                item = (UpStatsItem *) g_ptr_array_index (array, i);
                point = gpm_point_obj_new ();
                point->x = i;
@@ -1096,7 +1088,7 @@ static gchar *
 gpm_stats_format_cmdline (UpWakeupItem *item)
 {
        gchar *found;
-       gchar *temp = NULL;
+       g_autofree gchar *temp = NULL;
        gchar *cmdline;
        const gchar *temp_ptr;
 
@@ -1156,7 +1148,6 @@ out:
                cmdline = g_markup_escape_text (temp_ptr, -1);
        else
                cmdline = g_markup_printf_escaped ("<i>%s</i>", temp_ptr);
-       g_free (temp);
 
        /* return */
        return cmdline;
@@ -1263,11 +1254,11 @@ static void
 gpm_stats_add_wakeups_item (UpWakeupItem *item)
 {
        const gchar *icon;
-       gchar *value;
-       gchar *id;
-       gchar *details;
-       gchar *cmdline;
        GtkTreeIter iter;
+       g_autofree gchar *cmdline = NULL;
+       g_autofree gchar *details = NULL;
+       g_autofree gchar *id = NULL;
+       g_autofree gchar *value = NULL;
 
        if (up_wakeup_item_get_is_userspace (item)) {
                icon = "application-x-executable";
@@ -1294,10 +1285,6 @@ gpm_stats_add_wakeups_item (UpWakeupItem *item)
                            GPM_WAKEUPS_COLUMN_CMDLINE, cmdline,
                            GPM_WAKEUPS_COLUMN_DETAILS, details,
                            GPM_WAKEUPS_COLUMN_ICON, icon, -1);
-       g_free (cmdline);
-       g_free (details);
-       g_free (value);
-       g_free (id);
 }
 
 /**
@@ -1310,7 +1297,6 @@ gpm_stats_update_wakeups_data (void)
        GtkWidget *page_widget;
        guint total;
        UpWakeupItem *item;
-       gchar *text;
        guint i;
        GError *error = NULL;
        GPtrArray *array;
@@ -1333,9 +1319,8 @@ gpm_stats_update_wakeups_data (void)
        total = up_wakeups_get_total_sync (wakeups, NULL, &error);
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_total_wakeups"));
        if (error == NULL) {
+               g_autofree gchar *text = NULL;
                text = g_strdup_printf ("%i", total);
-               gtk_label_set_label (GTK_LABEL(widget), text);
-               g_free (text);
        } else {
                gtk_label_set_label (GTK_LABEL(widget), error->message);
                g_error_free (error);
@@ -1346,7 +1331,7 @@ gpm_stats_update_wakeups_data (void)
        array = up_wakeups_get_data_sync (wakeups, NULL, NULL);
        if (array == NULL)
                return;
-       for (i=0; i<array->len; i++) {
+       for (i = 0; i < array->len; i++) {
                item = g_ptr_array_index (array, i);
                gpm_stats_add_wakeups_item (item);
        }
@@ -1356,7 +1341,7 @@ gpm_stats_update_wakeups_data (void)
 static void
 gpm_stats_set_title (GtkWindow *window, gint page_num)
 {
-       gchar *title;
+       g_autofree gchar *title = NULL;
        const gchar * const page_titles[] = {
                /* TRANSLATORS: shown on the titlebar */
                N_("Device Information"),
@@ -1371,7 +1356,6 @@ gpm_stats_set_title (GtkWindow *window, gint page_num)
        /* TRANSLATORS: shown on the titlebar */
        title = g_strdup_printf ("%s - %s", _("Power Statistics"), _(page_titles[page_num]));
        gtk_window_set_title (window, title);
-       g_free (title);
 }
 
 /**
@@ -1476,8 +1460,8 @@ gpm_stats_add_device (UpDevice *device)
        const gchar *id;
        GtkTreeIter iter;
        const gchar *text;
-       GIcon *icon;
        UpDeviceKind kind;
+       g_autoptr(GIcon) icon;
 
        /* get device properties */
        g_object_get (device,
@@ -1496,7 +1480,6 @@ gpm_stats_add_device (UpDevice *device)
                            GPM_DEVICES_COLUMN_ID, id,
                            GPM_DEVICES_COLUMN_TEXT, text,
                            GPM_DEVICES_COLUMN_ICON, icon, -1);
-       g_object_unref (icon);
 }
 
 /**
@@ -1530,7 +1513,6 @@ gpm_stats_device_removed_cb (UpClient *_client, const gchar *object_path, gpoint
        GtkTreeIter iter;
        UpDevice *device_tmp;
        gboolean ret;
-       gchar *id = NULL;
        guint i;
 
        for (i = 0; i < devices->len; i++) {
@@ -1549,12 +1531,12 @@ gpm_stats_device_removed_cb (UpClient *_client, const gchar *object_path, gpoint
        /* search the list and remove the object path entry */
        ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store_devices), &iter);
        while (ret) {
+               g_autofree gchar *id = NULL;
                gtk_tree_model_get (GTK_TREE_MODEL (list_store_devices), &iter, GPM_DEVICES_COLUMN_ID, &id, 
-1);
                if (g_strcmp0 (id, object_path) == 0) {
                        gtk_list_store_remove (list_store_devices, &iter);
                        break;
                }
-               g_free (id);
                ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store_devices), &iter);
        };
 }
@@ -1565,7 +1547,7 @@ gpm_stats_device_removed_cb (UpClient *_client, const gchar *object_path, gpoint
 static void
 gpm_stats_history_type_combo_changed_cb (GtkWidget *widget, gpointer data)
 {
-       gchar *value;
+       g_autofree gchar *value = NULL;
        const gchar *axis_x = NULL;
        const gchar *axis_y = NULL;
        value = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (widget));
@@ -1604,7 +1586,6 @@ gpm_stats_history_type_combo_changed_cb (GtkWidget *widget, gpointer data)
        gtk_label_set_label (GTK_LABEL(widget), axis_y);
 
        gpm_stats_button_update_ui ();
-       g_free (value);
 
        /* save to gconf */
        g_settings_set_string (settings, GPM_SETTINGS_INFO_HISTORY_TYPE, history_type);
@@ -1616,7 +1597,7 @@ gpm_stats_history_type_combo_changed_cb (GtkWidget *widget, gpointer data)
 static void
 gpm_stats_type_combo_changed_cb (GtkWidget *widget, gpointer data)
 {
-       gchar *value;
+       g_autofree gchar *value = NULL;
        const gchar *axis_x = NULL;
        const gchar *axis_y = NULL;
        value = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (widget));
@@ -1655,7 +1636,6 @@ gpm_stats_type_combo_changed_cb (GtkWidget *widget, gpointer data)
        gtk_label_set_label (GTK_LABEL(widget), axis_y);
 
        gpm_stats_button_update_ui ();
-       g_free (value);
 
        /* save to gconf */
        g_settings_set_string (settings, GPM_SETTINGS_INFO_STATS_TYPE, stats_type);
@@ -1667,7 +1647,7 @@ gpm_stats_type_combo_changed_cb (GtkWidget *widget, gpointer data)
 static void
 gpm_stats_range_combo_changed (GtkWidget *widget, gpointer data)
 {
-       gchar *value;
+       g_autofree gchar *value = NULL;
        value = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (widget));
        if (g_strcmp0 (value, GPM_HISTORY_MINUTE_TEXT) == 0)
                history_time = GPM_HISTORY_MINUTE_VALUE;
@@ -1686,7 +1666,6 @@ gpm_stats_range_combo_changed (GtkWidget *widget, gpointer data)
        g_settings_set_int (settings, GPM_SETTINGS_INFO_HISTORY_TIME, history_time);
 
        gpm_stats_button_update_ui ();
-       g_free (value);
 }
 
 /**
@@ -1749,8 +1728,6 @@ gpm_stats_highlight_device (const gchar *object_path)
 {
        gboolean ret;
        gboolean found = FALSE;
-       gchar *id = NULL;
-       gchar *path_str;
        guint i;
        GtkTreeIter iter;
        GtkTreePath *path;
@@ -1764,20 +1741,20 @@ gpm_stats_highlight_device (const gchar *object_path)
 
        /* we have to reuse the treeview data as it may be sorted */
        ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store_devices), &iter);
-       for (i=0; ret && !found; i++) {
+       for (i = 0; ret && !found; i++) {
+               g_autofree gchar *id = NULL;
                gtk_tree_model_get (GTK_TREE_MODEL (list_store_devices), &iter,
                                    GPM_DEVICES_COLUMN_ID, &id,
                                    -1);
                if (g_strcmp0 (id, object_path) == 0) {
+                       g_autofree gchar *path_str = NULL;
                        path_str = g_strdup_printf ("%i", i);
                        path = gtk_tree_path_new_from_string (path_str);
                        widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices"));
                        gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (widget), path, NULL, NULL, FALSE);
-                       g_free (path_str);
                        gtk_tree_path_free (path);
                        found = TRUE;
                }
-               g_free (id);
                ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store_devices), &iter);
        }
 out:
@@ -1794,11 +1771,11 @@ gpm_stats_commandline_cb (GApplication *application,
 {
        gboolean ret;
        gboolean verbose = FALSE;
-       gchar **argv;
-       gchar *last_device =  NULL;
        gint argc;
-       GOptionContext *context;
        GtkWindow *window;
+       g_auto(GStrv) argv;
+       g_autofree gchar *last_device =  NULL;
+       g_autoptr(GOptionContext) context;
 
        const GOptionEntry options[] = {
                { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
@@ -1817,9 +1794,8 @@ gpm_stats_commandline_cb (GApplication *application,
        /* TRANSLATORS: the program name */
        g_option_context_set_summary (context, _("Power Statistics"));
        g_option_context_add_main_entries (context, options, NULL);
-       ret = g_option_context_parse (context, &argc, &argv, NULL);
-       if (!ret)
-               goto out;
+       if (!g_option_context_parse (context, &argc, &argv, NULL))
+               return FALSE;
 
        /* get from GSettings if we never specified on the command line */
        if (last_device == NULL)
@@ -1828,18 +1804,16 @@ gpm_stats_commandline_cb (GApplication *application,
        /* set the correct focus on the last device */
        if (last_device != NULL) {
                ret = gpm_stats_highlight_device (last_device);
-               if (!ret)
+               if (!ret) {
                        g_warning ("failed to select");
-               g_free (last_device);
+                       return FALSE;
+               }
        }
 
        /* make sure the window is raised */
        window = GTK_WINDOW (gtk_builder_get_object (builder, "dialog_stats"));
        gtk_window_present (window);
-out:
-       g_strfreev (argv);
-       g_option_context_free (context);
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -2050,7 +2024,7 @@ gpm_stats_startup_cb (GApplication *application,
        ret = up_wakeups_get_has_capability (wakeups);
        if (ret) {
                GtkTreeIter iter;
-               GIcon *icon;
+               g_autoptr(GIcon) icon;
                icon = g_themed_icon_new ("computer");
                gtk_list_store_append (list_store_devices, &iter);
                gtk_list_store_set (list_store_devices, &iter,
@@ -2058,7 +2032,6 @@ gpm_stats_startup_cb (GApplication *application,
                                    /* TRANSLATORS: the icon for the CPU */
                                    GPM_DEVICES_COLUMN_TEXT, _("Processor"),
                                    GPM_DEVICES_COLUMN_ICON, icon, -1);
-               g_object_unref (icon);
        }
 
        /* set axis */
@@ -2078,7 +2051,7 @@ gpm_stats_startup_cb (GApplication *application,
 int
 main (int argc, char *argv[])
 {
-       GtkApplication *application;
+       g_autoptr(GtkApplication) application;
        int status = 0;
 
        setlocale (LC_ALL, "");
@@ -2112,6 +2085,5 @@ main (int argc, char *argv[])
        if (devices != NULL)
                g_ptr_array_unref (devices);
        g_object_unref (settings);
-       g_object_unref (application);
        return status;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]