[gnome-color-manager] Use g_autoptr()



commit 3f606e546b96d85931105e4ee31c79f52117a63a
Author: Richard Hughes <richard hughsie com>
Date:   Sun Oct 25 21:01:51 2015 +0000

    Use g_autoptr()

 src/gcm-brightness.c                 |   23 ++--
 src/gcm-brightness.h                 |   20 +--
 src/gcm-calibrate-argyll.c           |  290 ++++++++++++----------------------
 src/gcm-calibrate-main.c             |  163 ++++++-------------
 src/gcm-calibrate.c                  |  214 ++++++++++++-------------
 src/gcm-calibrate.h                  |   20 +--
 src/gcm-cell-renderer-color.c        |    6 +-
 src/gcm-cell-renderer-profile-text.c |    4 +-
 src/gcm-cie-widget.c                 |    2 +-
 src/gcm-exif.c                       |   89 ++++------
 src/gcm-exif.h                       |   20 +--
 src/gcm-gamma-widget.c               |    2 +-
 src/gcm-import.c                     |   61 +++-----
 src/gcm-inspect.c                    |   63 +++-----
 src/gcm-picker.c                     |  118 +++++----------
 src/gcm-print.c                      |    7 +-
 src/gcm-self-test.c                  |   54 ++-----
 src/gcm-utils.c                      |   77 +++------
 src/gcm-viewer.c                     |  207 ++++++++-----------------
 19 files changed, 504 insertions(+), 936 deletions(-)
---
diff --git a/src/gcm-brightness.c b/src/gcm-brightness.c
index f542ba7..2eb5f17 100644
--- a/src/gcm-brightness.c
+++ b/src/gcm-brightness.c
@@ -28,13 +28,11 @@
 
 static void     gcm_brightness_finalize        (GObject     *object);
 
-#define GCM_BRIGHTNESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_BRIGHTNESS, 
GcmBrightnessPrivate))
-
-struct _GcmBrightnessPrivate
+typedef struct
 {
        guint                            percentage;
        GDBusConnection                 *connection;
-};
+} GcmBrightnessPrivate;
 
 enum {
        PROP_0,
@@ -42,7 +40,8 @@ enum {
        PROP_LAST
 };
 
-G_DEFINE_TYPE (GcmBrightness, gcm_brightness, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GcmBrightness, gcm_brightness, G_TYPE_OBJECT)
+#define GET_PRIVATE(o) (gcm_brightness_get_instance_private (o))
 
 #define        GPM_DBUS_SERVICE                "org.gnome.SettingsDaemon"
 #define        GPM_DBUS_INTERFACE_BACKLIGHT    "org.gnome.SettingsDaemon.Power.Screen"
@@ -51,7 +50,7 @@ G_DEFINE_TYPE (GcmBrightness, gcm_brightness, G_TYPE_OBJECT)
 gboolean
 gcm_brightness_set_percentage (GcmBrightness *brightness, guint percentage, GError **error)
 {
-       GcmBrightnessPrivate *priv = brightness->priv;
+       GcmBrightnessPrivate *priv = GET_PRIVATE (brightness);
        gboolean ret = FALSE;
        GVariant *response = NULL;
 
@@ -89,7 +88,7 @@ out:
 gboolean
 gcm_brightness_get_percentage (GcmBrightness *brightness, guint *percentage, GError **error)
 {
-       GcmBrightnessPrivate *priv = brightness->priv;
+       GcmBrightnessPrivate *priv = GET_PRIVATE (brightness);
        gboolean ret = FALSE;
        GVariant *response = NULL;
 
@@ -134,7 +133,7 @@ static void
 gcm_brightness_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 {
        GcmBrightness *brightness = GCM_BRIGHTNESS (object);
-       GcmBrightnessPrivate *priv = brightness->priv;
+       GcmBrightnessPrivate *priv = GET_PRIVATE (brightness);
 
        switch (prop_id) {
        case PROP_PERCENTAGE:
@@ -172,22 +171,20 @@ gcm_brightness_class_init (GcmBrightnessClass *klass)
                                   0, 100, 0,
                                   G_PARAM_READABLE);
        g_object_class_install_property (object_class, PROP_PERCENTAGE, pspec);
-
-       g_type_class_add_private (klass, sizeof (GcmBrightnessPrivate));
 }
 
 static void
 gcm_brightness_init (GcmBrightness *brightness)
 {
-       brightness->priv = GCM_BRIGHTNESS_GET_PRIVATE (brightness);
-       brightness->priv->percentage = 0;
+       GcmBrightnessPrivate *priv = GET_PRIVATE (brightness);
+       priv->percentage = 0;
 }
 
 static void
 gcm_brightness_finalize (GObject *object)
 {
        GcmBrightness *brightness = GCM_BRIGHTNESS (object);
-       GcmBrightnessPrivate *priv = brightness->priv;
+       GcmBrightnessPrivate *priv = GET_PRIVATE (brightness);
 
        if (priv->connection != NULL)
                g_object_unref (priv->connection);
diff --git a/src/gcm-brightness.h b/src/gcm-brightness.h
index e72ac6b..ef0d50c 100644
--- a/src/gcm-brightness.h
+++ b/src/gcm-brightness.h
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2009-2010 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2009-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -26,22 +26,8 @@
 
 G_BEGIN_DECLS
 
-#define GCM_TYPE_BRIGHTNESS            (gcm_brightness_get_type ())
-#define GCM_BRIGHTNESS(o)              (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_BRIGHTNESS, GcmBrightness))
-#define GCM_BRIGHTNESS_CLASS(k)                (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_BRIGHTNESS, 
GcmBrightnessClass))
-#define GCM_IS_BRIGHTNESS(o)           (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_BRIGHTNESS))
-#define GCM_IS_BRIGHTNESS_CLASS(k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_BRIGHTNESS))
-#define GCM_BRIGHTNESS_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_BRIGHTNESS, 
GcmBrightnessClass))
-
-typedef struct _GcmBrightnessPrivate   GcmBrightnessPrivate;
-typedef struct _GcmBrightness          GcmBrightness;
-typedef struct _GcmBrightnessClass     GcmBrightnessClass;
-
-struct _GcmBrightness
-{
-        GObject                 parent;
-        GcmBrightnessPrivate   *priv;
-};
+#define GCM_TYPE_BRIGHTNESS (gcm_brightness_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GcmBrightness, gcm_brightness, GCM, BRIGHTNESS, GObject)
 
 struct _GcmBrightnessClass
 {
diff --git a/src/gcm-calibrate-argyll.c b/src/gcm-calibrate-argyll.c
index 9765d37..4fee1ed 100644
--- a/src/gcm-calibrate-argyll.c
+++ b/src/gcm-calibrate-argyll.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2009-2012 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2009-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -204,7 +204,7 @@ gcm_calibrate_argyll_get_display (const gchar *output_name,
 
        /* split it into lines */
        split = g_strsplit (data, "\n", -1);
-       for (i=0; split[i] != NULL; i++) {
+       for (i = 0; split[i] != NULL; i++) {
                if (g_strstr_len (split[i], -1, "XRandR 1.2 is faulty") != NULL) {
                        g_set_error_literal (error,
                                             GCM_CALIBRATE_ERROR,
@@ -824,35 +824,26 @@ gcm_utils_mkdir_and_copy (GFile *source,
                          GFile *destination,
                          GError **error)
 {
-       gboolean ret;
-       GFile *parent;
+       g_autoptr(GFile) parent = NULL;
 
        g_return_val_if_fail (source != NULL, FALSE);
        g_return_val_if_fail (destination != NULL, FALSE);
 
-       /* get parent */
-       parent = g_file_get_parent (destination);
-
        /* create directory */
+       parent = g_file_get_parent (destination);
        if (!g_file_query_exists (parent, NULL)) {
-               ret = g_file_make_directory_with_parents (parent, NULL, error);
-               if (!ret)
-                       goto out;
+               if (!g_file_make_directory_with_parents (parent, NULL, error))
+                       return FALSE;
        }
 
        /* do the copy */
-       ret = g_file_copy (source,
-                          destination,
-                          G_FILE_COPY_OVERWRITE,
-                          NULL,
-                          NULL,
-                          NULL,
-                          error);
-       if (!ret)
-               goto out;
-out:
-       g_object_unref (parent);
-       return ret;
+       return g_file_copy (source,
+                           destination,
+                           G_FILE_COPY_OVERWRITE,
+                           NULL,
+                           NULL,
+                           NULL,
+                           error);
 }
 
 /**
@@ -862,21 +853,20 @@ static gboolean
 gcm_calibrate_argyll_device_copy (GcmCalibrateArgyll *calibrate_argyll,
                                  GError **error)
 {
-       gboolean ret;
-       gchar *device = NULL;
-       gchar *destination_cht = NULL;
-       gchar *destination_ref = NULL;
-       gchar *filename = NULL;
-       gchar *basename = NULL;
-       gchar *filename_cht = NULL;
-       gchar *filename_source = NULL;
-       gchar *filename_reference = NULL;
-       GFile *file_cht = NULL;
-       GFile *file_source = NULL;
-       GFile *file_reference = NULL;
-       GFile *dest_cht = NULL;
-       GFile *dest_source = NULL;
-       GFile *dest_reference = NULL;
+       g_autofree gchar *device = NULL;
+       g_autofree gchar *destination_cht = NULL;
+       g_autofree gchar *destination_ref = NULL;
+       g_autofree gchar *filename = NULL;
+       g_autofree gchar *basename = NULL;
+       g_autofree gchar *filename_cht = NULL;
+       g_autofree gchar *filename_source = NULL;
+       g_autofree gchar *filename_reference = NULL;
+       g_autoptr(GFile) file_cht = NULL;
+       g_autoptr(GFile) file_source = NULL;
+       g_autoptr(GFile) file_reference = NULL;
+       g_autoptr(GFile) dest_cht = NULL;
+       g_autoptr(GFile) dest_source = NULL;
+       g_autoptr(GFile) dest_reference = NULL;
        const gchar *working_path;
        const gchar *filename_tmp;
        GcmCalibrateReferenceKind reference_kind;
@@ -910,40 +900,20 @@ gcm_calibrate_argyll_device_copy (GcmCalibrateArgyll *calibrate_argyll,
        filename_tmp = gcm_calibrate_argyll_reference_kind_to_filename (reference_kind);
        filename_cht = g_build_filename ("/usr/share/color/argyll/ref", filename_tmp, NULL);
 
-       /* convert to GFile */
+       /* do the copies */
        file_cht = g_file_new_for_path (filename_cht);
-       file_source = g_file_new_for_path (filename_source);
-       file_reference = g_file_new_for_path (filename_reference);
        dest_cht = g_file_new_for_path (destination_cht);
+       if (!gcm_utils_mkdir_and_copy (file_cht, dest_cht, error))
+               return FALSE;
+       file_source = g_file_new_for_path (filename_source);
        dest_source = g_file_new_for_path (device);
+       if (!gcm_utils_mkdir_and_copy (file_source, dest_source, error))
+               return FALSE;
+       file_reference = g_file_new_for_path (filename_reference);
        dest_reference = g_file_new_for_path (destination_ref);
-
-       /* do the copy */
-       ret = gcm_utils_mkdir_and_copy (file_cht, dest_cht, error);
-       if (!ret)
-               goto out;
-       ret = gcm_utils_mkdir_and_copy (file_source, dest_source, error);
-       if (!ret)
-               goto out;
-       ret = gcm_utils_mkdir_and_copy (file_reference, dest_reference, error);
-       if (!ret)
-               goto out;
-out:
-       g_free (basename);
-       g_free (filename);
-       g_free (filename_cht);
-       g_free (filename_source);
-       g_free (filename_reference);
-       g_free (device);
-       g_free (destination_cht);
-       g_free (destination_ref);
-       g_object_unref (file_cht);
-       g_object_unref (file_source);
-       g_object_unref (file_reference);
-       g_object_unref (dest_cht);
-       g_object_unref (dest_source);
-       g_object_unref (dest_reference);
-       return ret;
+       if (!gcm_utils_mkdir_and_copy (file_reference, dest_reference, error))
+               return FALSE;
+        return TRUE;
 }
 
 /**
@@ -1226,7 +1196,7 @@ gcm_calibrate_argyll_remove_temp_files (GcmCalibrateArgyll *calibrate_argyll,
 
        /* remove all the temp files */
        if (basename != NULL) {
-               for (i=0; exts[i] != NULL; i++) {
+               for (i = 0; exts[i] != NULL; i++) {
                        filename_tmp = g_strdup_printf ("%s/%s.%s", working_path, basename, exts[i]);
                        ret = g_file_test (filename_tmp, G_FILE_TEST_IS_REGULAR);
                        if (ret) {
@@ -1238,7 +1208,7 @@ gcm_calibrate_argyll_remove_temp_files (GcmCalibrateArgyll *calibrate_argyll,
        }
 
        /* remove all the temp files */
-       for (i=0; filenames[i] != NULL; i++) {
+       for (i = 0; filenames[i] != NULL; i++) {
                filename_tmp = g_strdup_printf ("%s/%s", working_path, filenames[i]);
                ret = g_file_test (filename_tmp, G_FILE_TEST_IS_REGULAR);
                if (ret) {
@@ -1531,21 +1501,16 @@ out:
 static gboolean
 gcm_calibrate_argyll_get_enabled (GcmCalibrate *calibrate)
 {
-       gboolean ret = TRUE;
-       gchar *command;
-       GError *error = NULL;
+       g_autofree gchar *command = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("dispcal", &error);
        if (command == NULL) {
                g_debug ("Failed to find dispcal: %s", error->message);
-               g_error_free (error);
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
-out:
-       g_free (command);
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -1631,7 +1596,7 @@ gcm_calibrate_argyll_set_device_from_ti2 (GcmCalibrate *calibrate,
 
        /* find the data */
        lines = g_strsplit (contents, "\n", -1);
-       for (i=0; lines[i] != NULL; i++) {
+       for (i = 0; lines[i] != NULL; i++) {
                if (g_str_has_prefix (lines[i], "TARGET_INSTRUMENT")) {
                        device = g_strdup (lines[i] + 18);
                        g_strdelimit (device, "\"", ' ');
@@ -1672,21 +1637,17 @@ out:
 static GtkPaperSize *
 gcm_calibrate_argyll_get_paper_size (GcmCalibrate *calibrate, GtkWindow *window)
 {
-       GtkPrintSettings *settings;
+       g_autoptr(GtkPrintSettings) settings = NULL;
        GtkPageSetup *page_setup;
-       GtkPaperSize *paper_size = NULL;
 
        /* find out the paper size */
        settings = gtk_print_settings_new ();
        page_setup = gtk_print_run_page_setup_dialog (window, NULL, settings);
        if (page_setup == NULL)
-               goto out;
+               return NULL;
 
        /* get paper size */
-       paper_size = gtk_page_setup_get_paper_size (page_setup);
-out:
-       g_object_unref (settings);
-       return paper_size;
+       return gtk_page_setup_get_paper_size (page_setup);
 }
 
 /**
@@ -1696,26 +1657,24 @@ static gboolean
 gcm_calibrate_argyll_printer_convert_jpeg (GcmCalibrateArgyll *calibrate_argyll,
                                           GError **error)
 {
-       GDir *dir;
+       g_autoptr(GDir) dir = NULL;
        const gchar *filename;
-       gchar *filename_tiff;
-       gchar *filename_jpg;
        guint len;
        gboolean ret = TRUE;
        const gchar *working_path;
-       GdkPixbuf *pixbuf;
 
        /* need to ask if we are printing now, or using old data */
        working_path = gcm_calibrate_get_working_path (GCM_CALIBRATE (calibrate_argyll));
        dir = g_dir_open (working_path, 0, error);
-       if (dir == NULL) {
-               ret = FALSE;
-               goto out;
-       }
+       if (dir == NULL)
+               return FALSE;
 
        filename = g_dir_read_name (dir);
        while (filename != NULL) {
                if (g_str_has_suffix (filename, ".tif")) {
+                       g_autoptr(GdkPixbuf) pixbuf = NULL;
+                       g_autofree gchar *filename_tiff = NULL;
+                       g_autofree gchar *filename_jpg = NULL;
 
                        /* get both files */
                        filename_tiff = g_build_filename (working_path, filename, NULL);
@@ -1728,10 +1687,8 @@ gcm_calibrate_argyll_printer_convert_jpeg (GcmCalibrateArgyll *calibrate_argyll,
                        /* convert from tiff to jpg */
                        g_debug ("convert %s to %s", filename_tiff, filename_jpg);
                        pixbuf = gdk_pixbuf_new_from_file (filename_tiff, error);
-                       if (pixbuf == NULL) {
-                               ret = FALSE;
-                               goto out;
-                       }
+                       if (pixbuf == NULL)
+                               return FALSE;
 
                        /* try to save new file */
                        ret = gdk_pixbuf_save (pixbuf,
@@ -1742,17 +1699,11 @@ gcm_calibrate_argyll_printer_convert_jpeg (GcmCalibrateArgyll *calibrate_argyll,
                                               "100",
                                               NULL);
                        if (!ret)
-                               goto out;
-                       g_object_unref (pixbuf);
-                       g_free (filename_tiff);
-                       g_free (filename_jpg);
+                               return FALSE;
                }
                filename = g_dir_read_name (dir);
        }
-out:
-       if (dir != NULL)
-               g_dir_close (dir);
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -1766,15 +1717,15 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
                              GError **error)
 {
        gboolean ret;
-       gchar *cmdline = NULL;
-       gchar *filename = NULL;
        const gchar *working_path;
-       gchar *basename = NULL;
        GtkPaperSize *paper_size;
        gdouble width, height;
        GcmCalibratePrintKind print_kind;
        GcmCalibrateArgyll *calibrate_argyll = GCM_CALIBRATE_ARGYLL(calibrate);
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
+       g_autofree gchar *basename = NULL;
+       g_autofree gchar *cmdline = NULL;
+       g_autofree gchar *filename = NULL;
 
        /* need to ask if we are printing now, or using old data */
        g_object_get (calibrate,
@@ -1792,7 +1743,7 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
                                                      calibrate,
                                                      error);
                if (!ret)
-                       goto out;
+                       return FALSE;
        }
 
        /* page setup, and then we're done */
@@ -1810,13 +1761,13 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
                                                                     height,
                                                                     error);
                if (!ret)
-                       goto out;
+                       return FALSE;
 
                /* convert to jpegs */
                ret = gcm_calibrate_argyll_printer_convert_jpeg (GCM_CALIBRATE_ARGYLL (calibrate),
                                                                 error);
                if (!ret)
-                       goto out;
+                       return FALSE;
 
                g_debug ("we need to open the directory we're using: %s", working_path);
                argv[1] = working_path;
@@ -1827,7 +1778,7 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
                                     NULL, NULL,
                                     NULL,
                                     error);
-               goto out;
+               return FALSE;
        }
 
        /* wait */
@@ -1856,11 +1807,11 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_NO_DATA,
                                     "cannot find %s", filename);
-                       goto out;
+                       return FALSE;
                }
                ret = gcm_calibrate_argyll_set_device_from_ti2 (calibrate, filename, error);
                if (!ret)
-                       goto out;
+                       return FALSE;
        }
 
        /* set progress */
@@ -1869,7 +1820,7 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
        /* step 3 */
        ret = gcm_calibrate_argyll_display_read_chart (calibrate_argyll, error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* set progress */
        gcm_calibrate_set_progress (calibrate, 80);
@@ -1878,7 +1829,7 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
        ret = gcm_calibrate_argyll_device_generate_profile (calibrate_argyll,
                                                            error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* only delete state if we are doing a local printer */
        if (print_kind == GCM_CALIBRATE_PRINT_KIND_LOCAL) {
@@ -1886,19 +1837,15 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
                ret = gcm_calibrate_argyll_remove_temp_files (calibrate_argyll,
                                                              error);
                if (!ret)
-                       goto out;
+                       return FALSE;
        }
 
        /* step 6 */
        ret = gcm_calibrate_argyll_set_filename_result (calibrate_argyll,
                                                        error);
        if (!ret)
-               goto out;
-out:
-       g_free (filename);
-       g_free (basename);
-       g_free (cmdline);
-       return ret;
+               return FALSE;
+       return TRUE;
 }
 
 /**
@@ -1946,12 +1893,11 @@ gcm_calibrate_argyll_check_and_remove_alpha (GcmCalibrateArgyll *calibrate_argyl
                                             GError **error)
 {
        const gchar *working_path;
-       gboolean ret = TRUE;
-       gchar *basename = NULL;
-       gchar *filename = NULL;
-       gchar *reference_image = NULL;
-       GdkPixbuf *pixbuf_new = NULL;
-       GdkPixbuf *pixbuf = NULL;
+       g_autofree gchar *basename = NULL;
+       g_autofree gchar *filename = NULL;
+       g_autofree gchar *reference_image = NULL;
+       g_autoptr(GdkPixbuf) pixbuf_new = NULL;
+       g_autoptr(GdkPixbuf) pixbuf = NULL;
 
        /* get shared data */
        g_object_get (calibrate_argyll,
@@ -1965,14 +1911,12 @@ gcm_calibrate_argyll_check_and_remove_alpha (GcmCalibrateArgyll *calibrate_argyl
 
        /* check to see if the file has any alpha channel */
        pixbuf = gdk_pixbuf_new_from_file (reference_image, error);
-       if (pixbuf == NULL) {
-               ret = FALSE;
-               goto out;
-       }
+       if (pixbuf == NULL)
+               return FALSE;
 
        /* plain RGB */
        if (!gdk_pixbuf_get_has_alpha (pixbuf))
-               goto out;
+               return TRUE;
 
        /* remove the alpha channel */
        pixbuf_new = gcm_calibrate_argyll_pixbuf_remove_alpha (pixbuf);
@@ -1981,24 +1925,11 @@ gcm_calibrate_argyll_check_and_remove_alpha (GcmCalibrateArgyll *calibrate_argyl
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_INTERNAL,
                                     "failed to remove alpha channel");
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 
        /* save */
-       ret = gdk_pixbuf_save (pixbuf_new, reference_image, "tiff", error, NULL);
-       if (!ret)
-               goto out;
-
-out:
-       g_free (filename);
-       g_free (basename);
-       g_free (reference_image);
-       if (pixbuf != NULL)
-               g_object_unref (pixbuf);
-       if (pixbuf_new != NULL)
-               g_object_unref (pixbuf_new);
-       return ret;
+       return gdk_pixbuf_save (pixbuf_new, reference_image, "tiff", error, NULL);
 }
 
 /**
@@ -2196,35 +2127,31 @@ static gboolean
 gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
                                         const gchar *line)
 {
-       gchar *title_str = NULL;
-       GString *string = NULL;
        gchar *found;
-       gchar **split = NULL;
-       gboolean ret = TRUE;
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
+       g_autofree gchar *title_str = NULL;
+       g_auto(GStrv) split = NULL;
+       g_autoptr(GString) string = NULL;
 
        /* attach device */
        if (g_strcmp0 (line, "Place instrument on test window.") == 0) {
                g_debug ("VTE: interaction required: %s", line);
                gcm_calibrate_argyll_interaction_attach (calibrate_argyll);
-               ret = FALSE;
-               goto out;
+               return TRUE;
        }
 
        /* set to calibrate */
        if (g_strcmp0 (line, "Set instrument sensor to calibration position,") == 0) {
                g_debug ("VTE: interaction required, set to calibrate");
                gcm_calibrate_argyll_interaction_calibrate (calibrate_argyll);
-               ret = FALSE;
-               goto out;
+               return TRUE;
        }
 
        /* set to calibrate */
        if (g_strcmp0 (line, "(Sensor should be in surface position)") == 0) {
                g_debug ("VTE: interaction required, set to surface");
                gcm_calibrate_argyll_interaction_surface (calibrate_argyll);
-               ret = FALSE;
-               goto out;
+               return TRUE;
        }
 
        /* something went wrong with a measurement */
@@ -2251,7 +2178,7 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
                                 /* TRANSLATORS: this is the application name for libcanberra */
                                 CA_PROP_APPLICATION_NAME, _("GNOME Color Manager"),
                                 CA_PROP_EVENT_DESCRIPTION, "unspecified error", NULL);
-               goto out;
+               return TRUE;
        }
 
        /* lines we're ignoring */
@@ -2268,13 +2195,13 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
            g_str_has_prefix (line, "Perspective correction factors") ||
            g_str_has_suffix (line, "key to continue:")) {
                g_debug ("VTE: ignore: %s", line);
-               goto out;
+               return TRUE;
        }
 
        /* spot read result */
        found = g_strstr_len (line, -1, "Result is XYZ");
        if (found != NULL) {
-               CdColorXYZ *xyz;
+               g_autoptr(CdColorXYZ) xyz = NULL;
                g_warning ("line=%s", line);
                split = g_strsplit (line, " ", -1);
                xyz = cd_color_xyz_new ();
@@ -2287,8 +2214,7 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
                              "xyz", xyz,
                              NULL);
                priv->done_spot_read = TRUE;
-               cd_color_xyz_free (xyz);
-               goto out;
+               return TRUE;
        }
 
        /* error */
@@ -2342,7 +2268,7 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
 
                /* wait until finished */
                g_main_loop_run (priv->loop);
-               goto out;
+               return TRUE;
        }
 
        /* all done */
@@ -2350,7 +2276,7 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
        if (found != NULL) {
                gcm_calibrate_set_image (GCM_CALIBRATE (calibrate_argyll), "scan-target-good.svg");
                vte_terminal_feed_child (VTE_TERMINAL(priv->terminal), "d", 1);
-               goto out;
+               return TRUE;
        }
 
        /* reading strip */
@@ -2376,7 +2302,7 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
                                 /* TRANSLATORS: this is the application name for libcanberra */
                                 CA_PROP_APPLICATION_NAME, _("GNOME Color Manager"),
                                 CA_PROP_EVENT_DESCRIPTION, "failed to read strip", NULL);
-               goto out;
+               return TRUE;
        }
 
        /* reading sample */
@@ -2402,7 +2328,7 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
                                 /* TRANSLATORS: this is the application name for libcanberra */
                                 CA_PROP_APPLICATION_NAME, _("GNOME Color Manager"),
                                 CA_PROP_EVENT_DESCRIPTION, "failed to read sample", NULL);
-               goto out;
+               return TRUE;
        }
 
        /* reading strip */
@@ -2432,14 +2358,14 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
                priv->argyllcms_ok = "\n";
                priv->state = GCM_CALIBRATE_ARGYLL_STATE_WAITING_FOR_STDIN;
                gcm_calibrate_interaction_required (GCM_CALIBRATE (calibrate_argyll), _("Retry"));
-               goto out;
+               return TRUE;
        }
 
        /* reading spot */
        if (g_str_has_prefix (line, "Place instrument on spot to be measured")) {
                if (!priv->done_spot_read)
                        vte_terminal_feed_child (VTE_TERMINAL(priv->terminal), " ", 1);
-               goto out;
+               return TRUE;
        }
 
        /* reading strip */
@@ -2459,7 +2385,7 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
                priv->argyllcms_ok = " ";
                priv->state = GCM_CALIBRATE_ARGYLL_STATE_WAITING_FOR_STDIN;
                gcm_calibrate_interaction_required (GCM_CALIBRATE (calibrate_argyll), _("Retry"));
-               goto out;
+               return TRUE;
        }
 
        /* reading strip */
@@ -2487,7 +2413,7 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
 
                /* push new messages into the UI */
                gcm_calibrate_set_image (GCM_CALIBRATE (calibrate_argyll), "scan-target.svg");
-               goto out;
+               return TRUE;
        }
 
        /* update the percentage bar */
@@ -2505,17 +2431,12 @@ gcm_calibrate_argyll_process_output_cmd (GcmCalibrateArgyll *calibrate_argyll,
                        gcm_calibrate_set_progress (GCM_CALIBRATE (calibrate_argyll),
                                                    current * 100 / total);
                }
-               goto out;
+               return TRUE;
        }
 
        /* report a warning so friendly people report bugs */
        g_warning ("VTE: could not screenscrape: '%s'", line);
-out:
-       g_free (title_str);
-       g_strfreev (split);
-       if (string != NULL)
-               g_string_free (string, TRUE);
-       return ret;
+       return TRUE;
 }
 #endif
 
@@ -2539,14 +2460,14 @@ gcm_calibrate_argyll_selection_func_cb (VteTerminal *terminal,
 static void
 gcm_calibrate_argyll_flush_vte (GcmCalibrateArgyll *calibrate_argyll)
 {
-       gchar *output;
-       gchar **split;
        guint i;
        glong row;
        glong col;
        gboolean ret;
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
        VteTerminal *terminal = VTE_TERMINAL (priv->terminal);
+       g_autofree gchar *output = NULL;
+       g_auto(GStrv) split = NULL;
 
        /* select the text we've got since last time */
        vte_terminal_get_cursor_position (terminal, &col, &row);
@@ -2558,7 +2479,7 @@ gcm_calibrate_argyll_flush_vte (GcmCalibrateArgyll *calibrate_argyll)
                                              calibrate_argyll,
                                              NULL);
        split = g_strsplit (output, "\n", -1);
-       for (i=0; split[i] != NULL; i++) {
+       for (i = 0; split[i] != NULL; i++) {
                g_strchomp (split[i]);
                if (split[i][0] == '\0')
                        continue;
@@ -2570,9 +2491,6 @@ gcm_calibrate_argyll_flush_vte (GcmCalibrateArgyll *calibrate_argyll)
        /* save, so we don't re-process old text */
        priv->vte_previous_row = row;
        priv->vte_previous_col = col;
-
-       g_free (output);
-       g_strfreev (split);
 }
 
 /**
diff --git a/src/gcm-calibrate-main.c b/src/gcm-calibrate-main.c
index f6c30c1..4e652f7 100644
--- a/src/gcm-calibrate-main.c
+++ b/src/gcm-calibrate-main.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2009-2011 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2009-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -218,7 +218,7 @@ gcm_calib_get_vbox_for_page (GcmCalibratePriv *priv,
        GtkWidget *tmp;
        GcmCalibratePage page_tmp;
 
-       for (i=0; i<priv->pages->len; i++) {
+       for (i = 0; i<priv->pages->len; i++) {
                tmp = g_ptr_array_index (priv->pages, i);
                page_tmp = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (tmp),
                                                                "GcmCalibrateMain::Index"));
@@ -254,21 +254,16 @@ _cmsDictAddEntryAscii (cmsHANDLE dict,
                       const gchar *key,
                       const gchar *value)
 {
-       cmsBool ret = FALSE;
-       wchar_t *mb_key = NULL;
-       wchar_t *mb_value = NULL;
+       g_autofree wchar_t *mb_key = NULL;
+       g_autofree wchar_t *mb_value = NULL;
 
        mb_key = utf8_to_wchar_t (key);
        if (mb_key == NULL)
-               goto out;
+               return FALSE;
        mb_value = utf8_to_wchar_t (value);
        if (mb_value == NULL)
-               goto out;
-       ret = cmsDictAddEntry (dict, mb_key, mb_value, NULL, NULL);
-out:
-       g_free (mb_key);
-       g_free (mb_value);
-       return ret;
+               return FALSE;
+       return cmsDictAddEntry (dict, mb_key, mb_value, NULL, NULL);
 }
 
 static gboolean
@@ -279,11 +274,11 @@ gcm_calib_set_extra_metadata (GcmCalibratePriv *priv,
        cmsHANDLE dict = NULL;
        cmsHPROFILE lcms_profile;
        gboolean ret = TRUE;
-       gchar *data = NULL;
-       gchar *screen_brightness_str = NULL;
        gsize len;
        guint percentage;
        CdSensor *sensor;
+       g_autofree gchar *data = NULL;
+       g_autofree gchar *screen_brightness_str = NULL;
 
        /* parse */
        ret = g_file_get_contents (filename, &data, &len, error);
@@ -350,8 +345,6 @@ gcm_calib_set_extra_metadata (GcmCalibratePriv *priv,
        cmsSaveProfileToFile (lcms_profile, filename);
        ret = TRUE;
 out:
-       g_free (screen_brightness_str);
-       g_free (data);
        if (dict != NULL)
                cmsDictFree (dict);
        return ret;
@@ -367,14 +360,13 @@ gcm_calib_set_sensor_options_cb (GObject *object,
 {
        CdSensor *sensor = CD_SENSOR (object);
        gboolean ret;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* get return value */
        ret = cd_sensor_set_options_finish (sensor, res, &error);
        if (!ret) {
                g_warning ("Failed to set sensor option: %s",
                           error->message);
-               g_error_free (error);
        }
 }
 
@@ -384,16 +376,16 @@ gcm_calib_set_sensor_options (GcmCalibratePriv *priv,
 {
        CdSensor *sensor;
        gboolean ret;
-       gchar *data = NULL;
-       gchar *sha1 = NULL;
-       GError *error = NULL;
-       GHashTable *hash = NULL;
        gsize len;
+       g_autofree gchar *data = NULL;
+       g_autofree gchar *sha1 = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GHashTable) hash = NULL;
 
        /* get ChSensor */
        sensor = gcm_calibrate_get_sensor (priv->calibrate);
        if (sensor == NULL)
-               goto out;
+               return;
 
        /* set the remote profile hash */
        hash = g_hash_table_new_full (g_str_hash,
@@ -404,8 +396,7 @@ gcm_calib_set_sensor_options (GcmCalibratePriv *priv,
        if (!ret) {
                g_warning ("Failed to get SHA1 hash: %s",
                           error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
        sha1 = g_compute_checksum_for_data (G_CHECKSUM_SHA1,
                                            (const guchar *) data,
@@ -416,25 +407,20 @@ gcm_calib_set_sensor_options (GcmCalibratePriv *priv,
        cd_sensor_set_options (sensor, hash, NULL,
                               gcm_calib_set_sensor_options_cb,
                               priv);
-out:
-       g_free (data);
-       g_free (sha1);
-       if (hash != NULL)
-               g_hash_table_unref (hash);
 }
 
 static gboolean
 gcm_calib_start_idle_cb (gpointer user_data)
 {
-       CdProfile *profile = NULL;
+       g_autoptr(CdProfile) profile = NULL;
        const gchar *filename;
        gboolean ret;
        GcmCalibratePriv *priv = (GcmCalibratePriv *) user_data;
-       GError *error = NULL;
-       GFile *file = NULL;
        gint inhibit_cookie;
        GtkAssistant *assistant = GTK_ASSISTANT (priv->main_window);
        GtkWidget *vbox;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GFile) file = NULL;
 
        /* inhibit */
        inhibit_cookie = gtk_application_inhibit (priv->application,
@@ -462,7 +448,6 @@ gcm_calib_start_idle_cb (gpointer user_data)
 
                g_warning ("failed to calibrate: %s",
                           error->message);
-               g_error_free (error);
 
                /* mark this box as the end */
                vbox = gcm_calib_get_vbox_for_page (priv, GCM_CALIBRATE_PAGE_ACTION);
@@ -483,7 +468,6 @@ gcm_calib_start_idle_cb (gpointer user_data)
        if (!ret) {
                g_warning ("failed to set extra metadata: %s",
                           error->message);
-               g_error_free (error);
                goto out;
        }
 
@@ -499,7 +483,6 @@ gcm_calib_start_idle_cb (gpointer user_data)
        if (profile == NULL) {
                g_warning ("failed to find calibration profile: %s",
                           error->message);
-               g_error_free (error);
                goto out;
        }
        ret = cd_device_add_profile_sync (priv->device,
@@ -512,7 +495,6 @@ gcm_calib_start_idle_cb (gpointer user_data)
                           cd_profile_get_object_path (profile),
                           cd_device_get_object_path (priv->device),
                           error->message);
-               g_error_free (error);
                goto out;
        }
 
@@ -533,10 +515,6 @@ out:
                gtk_application_uninhibit (priv->application,
                                           priv->inhibit_cookie);
        }
-       if (profile != NULL)
-               g_object_unref (profile);
-       if (file != NULL)
-               g_object_unref (file);
        return FALSE;
 }
 
@@ -630,7 +608,7 @@ gcm_calib_add_page_title (GcmCalibratePriv *priv, const gchar *text)
        GtkWidget *label;
        GtkWidget *hbox;
        GtkWidget *vbox;
-       gchar *markup;
+       g_autofree gchar *markup = NULL;
 
        markup = g_strdup_printf ("<span size=\"large\" font_weight=\"bold\">%s</span>", text);
        label = gtk_label_new (NULL);
@@ -643,8 +621,6 @@ gcm_calib_add_page_title (GcmCalibratePriv *priv, const gchar *text)
        /* header */
        vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 20);
        gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-
-       g_free (markup);
        return vbox;
 }
 
@@ -654,7 +630,7 @@ gcm_calib_label_activate_link_cb (GtkLabel *label,
                                  GcmCalibratePriv *priv)
 {
        gboolean ret;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
        const gchar *argv[] = { BINDIR "/gnome-control-center color",
                                "color",
                                NULL };
@@ -668,7 +644,6 @@ gcm_calib_label_activate_link_cb (GtkLabel *label,
        if (!ret) {
                g_warning ("failed to launch the control center: %s",
                           error->message);
-               g_error_free (error);
        }
        return ret;
 }
@@ -704,10 +679,9 @@ gcm_calib_add_page_para (GtkWidget *vbox, const gchar *text)
 static void
 gcm_calib_add_page_bullet (GtkWidget *vbox, const gchar *text)
 {
-       gchar *markup;
+       g_autofree gchar *markup = NULL;
        markup = g_strdup_printf ("• %s", text);
        gcm_calib_add_page_para (vbox, markup);
-       g_free (markup);
 }
 
 /**
@@ -780,23 +754,17 @@ static gboolean
 gcm_calibrate_is_livecd (void)
 {
 #ifdef __linux__
-       gboolean ret;
-       gchar *data = NULL;
-       GError *error = NULL;
+       g_autofree gchar *data = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* get the kernel commandline */
-       ret = g_file_get_contents ("/proc/cmdline", &data, NULL, &error);
-       if (!ret) {
+       if (!g_file_get_contents ("/proc/cmdline", &data, NULL, &error)) {
                g_warning ("failed to get kernel command line: %s",
                           error->message);
-               g_error_free (error);
-               goto out;
+               return FALSE;
        }
-       ret = (g_strstr_len (data, -1, "liveimg") != NULL ||
-              g_strstr_len (data, -1, "casper") != NULL);
-out:
-       g_free (data);
-       return ret;
+       return (g_strstr_len (data, -1, "liveimg") != NULL ||
+               g_strstr_len (data, -1, "casper") != NULL);
 #else
        return FALSE;
 #endif
@@ -811,8 +779,8 @@ gcm_calib_show_profile_button_clicked_cb (GtkButton *button,
 {
        const gchar *argv[] = { BINDIR "/nautilus", "", NULL };
        gboolean ret;
-       gchar *path;
-       GError *error = NULL;
+       g_autofree gchar *path = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* just hardcode nautilus to open the folder */
        path = g_build_filename (g_get_user_data_dir (), "icc", NULL);
@@ -826,11 +794,8 @@ gcm_calib_show_profile_button_clicked_cb (GtkButton *button,
                             &error);
        if (!ret) {
                g_warning ("failed to show profile: %s", error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
-out:
-       g_free (path);
 }
 
 /**
@@ -1090,8 +1055,8 @@ gcm_calib_setup_page_install_argyllcms (GcmCalibratePriv *priv)
        GtkWidget *vbox;
        GtkWidget *content;
        GtkWidget *button;
-       GString *string;
        GtkAssistant *assistant = GTK_ASSISTANT (priv->main_window);
+       g_autoptr(GString) string = NULL;
 
        string = g_string_new ("");
 
@@ -1128,7 +1093,6 @@ gcm_calib_setup_page_install_argyllcms (GcmCalibratePriv *priv)
        g_object_set_data (G_OBJECT (vbox),
                           "GcmCalibrateMain::Index",
                           GUINT_TO_POINTER (GCM_CALIBRATE_PAGE_INSTALL_ARGYLLCMS));
-       g_string_free (string, TRUE);
 
        /* show page */
        gtk_widget_show_all (vbox);
@@ -1166,8 +1130,8 @@ gcm_calib_setup_page_install_targets (GcmCalibratePriv *priv)
        GtkWidget *vbox;
        GtkWidget *content;
        GtkWidget *button;
-       GString *string;
        GtkAssistant *assistant = GTK_ASSISTANT (priv->main_window);
+       g_autoptr(GString) string = NULL;
 
        string = g_string_new ("");
 
@@ -1206,7 +1170,6 @@ gcm_calib_setup_page_install_targets (GcmCalibratePriv *priv)
        g_object_set_data (G_OBJECT (vbox),
                           "GcmCalibrateMain::Index",
                           GUINT_TO_POINTER (GCM_CALIBRATE_PAGE_INSTALL_TARGETS));
-       g_string_free (string, TRUE);
 
        /* show page */
        gtk_widget_show_all (vbox);
@@ -1299,8 +1262,8 @@ gcm_calib_reference_kind_combobox_cb (GtkComboBox *combo_box,
                                      GcmCalibratePriv *priv)
 {
        const gchar *filename;
-       gchar *path;
        GcmCalibrateReferenceKind reference_kind;
+       g_autofree gchar *path = NULL;
 
        /* not sorted so we can just use the index */
        reference_kind = gtk_combo_box_get_active (GTK_COMBO_BOX (combo_box));
@@ -1315,7 +1278,6 @@ gcm_calib_reference_kind_combobox_cb (GtkComboBox *combo_box,
 
        path = g_build_filename (GCM_DATA, "targets", filename, NULL);
        gtk_image_set_from_file (GTK_IMAGE (priv->reference_preview), path);
-       g_free (path);
 }
 
 /**
@@ -1327,9 +1289,9 @@ gcm_calib_setup_page_target_kind (GcmCalibratePriv *priv)
        GtkWidget *vbox;
        GtkWidget *content;
        GtkWidget *combo;
-       GString *string;
        guint i;
        GtkAssistant *assistant = GTK_ASSISTANT (priv->main_window);
+       g_autoptr(GString) string = NULL;
 
        string = g_string_new ("");
 
@@ -1370,7 +1332,7 @@ gcm_calib_setup_page_target_kind (GcmCalibratePriv *priv)
        gtk_box_pack_start (GTK_BOX (vbox), priv->reference_preview, FALSE, FALSE, 0);
 
        combo = gtk_combo_box_text_new ();
-       for (i=0; i<GCM_CALIBRATE_REFERENCE_KIND_UNKNOWN; i++) {
+       for (i = 0; i<GCM_CALIBRATE_REFERENCE_KIND_UNKNOWN; i++) {
                gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo),
                                                gcm_calib_reference_kind_to_localised_string (i));
        }
@@ -1393,7 +1355,6 @@ gcm_calib_setup_page_target_kind (GcmCalibratePriv *priv)
        g_object_set_data (G_OBJECT (vbox),
                           "GcmCalibrateMain::Index",
                           GUINT_TO_POINTER (GCM_CALIBRATE_PAGE_TARGET_KIND));
-       g_string_free (string, TRUE);
 
        /* show page */
        gtk_widget_show_all (vbox);
@@ -1760,7 +1721,7 @@ gcm_calib_setup_page_precision (GcmCalibratePriv *priv)
        labels[2] = g_string_new (_("Quick"));
        switch (priv->device_kind) {
        case CD_DEVICE_KIND_PRINTER:
-               for (i=0; i<3; i++) {
+               for (i = 0; i<3; i++) {
                        g_string_append (labels[i], " ");
                        /* TRANSLATORS: radio options for calibration precision */
                        g_string_append_printf (labels[i], ngettext (
@@ -1771,7 +1732,7 @@ gcm_calib_setup_page_precision (GcmCalibratePriv *priv)
                }
                break;
        case CD_DEVICE_KIND_DISPLAY:
-               for (i=0; i<3; i++) {
+               for (i = 0; i<3; i++) {
                        g_string_append (labels[i], " ");
                        /* TRANSLATORS: radio options for calibration precision */
                        g_string_append_printf (labels[i], ngettext (
@@ -1823,7 +1784,7 @@ gcm_calib_setup_page_precision (GcmCalibratePriv *priv)
                           "GcmCalibrateMain::Index",
                           GUINT_TO_POINTER (GCM_CALIBRATE_PAGE_PRECISION));
 
-       for (i=0; i<3; i++)
+       for (i = 0; i<3; i++)
                g_string_free (labels[i], TRUE);
 
        /* show page */
@@ -1968,17 +1929,14 @@ static void
 gcm_calib_got_sensor (GcmCalibratePriv *priv, CdSensor *sensor)
 {
        gboolean is_lowend = FALSE;
-       gboolean ret;
-       GError *error = NULL;
        GtkWidget *vbox;
+       g_autoptr(GError) error = NULL;
 
        /* connect to sensor */
-       ret = cd_sensor_connect_sync (sensor, NULL, &error);
-       if (!ret) {
+       if (!cd_sensor_connect_sync (sensor, NULL, &error)) {
                g_warning ("failed to connect to sensor: %s",
                           error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
        gcm_calibrate_set_sensor (priv->calibrate, sensor);
 
@@ -1998,8 +1956,6 @@ gcm_calib_got_sensor (GcmCalibratePriv *priv, CdSensor *sensor)
                                                    GCM_CALIBRATE_PAGE_DISPLAY_TEMPERATURE);
                gtk_widget_set_visible (vbox, !is_lowend);
        }
-out:
-       return;
 }
 
 /**
@@ -2013,16 +1969,15 @@ gcm_calib_get_sensors_cb (GObject *object,
        CdClient *client = CD_CLIENT (object);
        CdSensor *sensor_tmp;
        GcmCalibratePriv *priv = (GcmCalibratePriv *) user_data;
-       GError *error = NULL;
-       GPtrArray *sensors;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GPtrArray) sensors = NULL;
 
        /* get the result */
        sensors = cd_client_get_sensors_finish (client, res, &error);
        if (sensors == NULL) {
                g_warning ("failed to get sensors: %s",
                           error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
 
        /* we've got a sensor */
@@ -2030,9 +1985,6 @@ gcm_calib_get_sensors_cb (GObject *object,
                sensor_tmp = g_ptr_array_index (sensors, 0);
                gcm_calib_got_sensor (priv, sensor_tmp);
        }
-out:
-       if (sensors != NULL)
-               g_ptr_array_unref (sensors);
 }
 
 /**
@@ -2114,16 +2066,15 @@ gcm_calib_startup_cb (GApplication *application, GcmCalibratePriv *priv)
 {
        const gint window_width  = 640;
        const gint window_height = 440;
-
        const gchar *description;
        const gchar *manufacturer;
        const gchar *model;
        const gchar *native_device;
        const gchar *serial;
-       gchar *copyright = NULL;
        gboolean ret;
-       GDateTime *dt = NULL;
-       GError *error = NULL;
+       g_autofree gchar *copyright = NULL;
+       g_autoptr(GDateTime) dt = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* add application specific icons to search path */
        gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
@@ -2137,9 +2088,7 @@ gcm_calib_startup_cb (GApplication *application, GcmCalibratePriv *priv)
                                      NULL,
                                      &error);
        if (!ret) {
-               g_warning ("failed to connect to colord: %s",
-                          error->message);
-               g_error_free (error);
+               g_warning ("failed to connect to colord: %s", error->message);
                goto out;
        }
 
@@ -2175,7 +2124,6 @@ gcm_calib_startup_cb (GApplication *application, GcmCalibratePriv *priv)
                g_warning ("failed to get device %s: %s",
                           priv->device_id,
                           error->message);
-               g_error_free (error);
                goto out;
        }
 
@@ -2186,7 +2134,6 @@ gcm_calib_startup_cb (GApplication *application, GcmCalibratePriv *priv)
        if (!ret) {
                g_warning ("failed to connect to device: %s",
                           error->message);
-               g_error_free (error);
                goto out;
        }
 
@@ -2257,9 +2204,6 @@ out:
        /* add different pages depending on the device kind */
        gcm_calib_add_pages (priv);
        gtk_assistant_set_current_page (GTK_ASSISTANT (priv->main_window), 0);
-       if (dt != NULL)
-               g_date_time_unref (dt);
-       g_free (copyright);
 }
 
 static void
@@ -2267,11 +2211,9 @@ gcm_calib_title_changed_cb (GcmCalibrate *calibrate,
                            const gchar *title,
                            GcmCalibratePriv *priv)
 {
-       gchar *markup;
-
+       g_autofree gchar *markup = NULL;
        markup = g_strdup_printf ("<span size=\"large\" font_weight=\"bold\">%s</span>", title);
        gtk_label_set_markup (GTK_LABEL (priv->action_title), markup);
-       g_free (markup);
 }
 
 static void
@@ -2296,14 +2238,13 @@ gcm_calib_image_changed_cb (GcmCalibrate *calibrate,
                            const gchar *filename,
                            GcmCalibratePriv *priv)
 {
-       GdkPixbuf *pixbuf;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
 
        if (filename != NULL) {
+               g_autoptr(GdkPixbuf) pixbuf = NULL;
                pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 200, 400, &error);
                if (pixbuf == NULL) {
                        g_warning ("failed to load image: %s", error->message);
-                       g_error_free (error);
                        gtk_widget_hide (priv->action_image);
                } else {
                        gtk_image_set_from_pixbuf (GTK_IMAGE (priv->action_image), pixbuf);
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 03387d0..4f48386 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2009-2012 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2009-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -41,7 +41,7 @@ static void     gcm_calibrate_finalize        (GObject     *object);
  *
  * Private #GcmCalibrate data
  **/
-struct _GcmCalibratePrivate
+typedef struct
 {
        GcmBrightness                   *brightness;
        GcmCalibrateDisplayKind          display_kind;
@@ -70,7 +70,7 @@ struct _GcmCalibratePrivate
        gchar                           *old_message;
        gchar                           *old_title;
        gboolean                         sensor_on_screen;
-};
+} GcmCalibratePrivate;
 
 enum {
        PROP_0,
@@ -107,18 +107,21 @@ enum {
 
 static guint signals[SIGNAL_LAST] = { 0 };
 
-G_DEFINE_TYPE (GcmCalibrate, gcm_calibrate, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GcmCalibrate, gcm_calibrate, G_TYPE_OBJECT)
+#define GET_PRIVATE(o) (gcm_calibrate_get_instance_private (o))
 
 void
 gcm_calibrate_set_content_widget (GcmCalibrate *calibrate, GtkWidget *widget)
 {
-       calibrate->priv->content_widget = widget;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
+       priv->content_widget = widget;
 }
 
 GtkWidget *
 gcm_calibrate_get_content_widget (GcmCalibrate *calibrate)
 {
-       return calibrate->priv->content_widget;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
+       return priv->content_widget;
 }
 
 /**
@@ -127,21 +130,15 @@ gcm_calibrate_get_content_widget (GcmCalibrate *calibrate)
 static gboolean
 gcm_calibrate_mkdir_with_parents (const gchar *filename, GError **error)
 {
-       gboolean ret;
-       GFile *file = NULL;
+       g_autoptr(GFile) file = NULL;
 
        /* ensure desination exists */
-       ret = g_file_test (filename, G_FILE_TEST_EXISTS);
-       if (!ret) {
+       if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
                file = g_file_new_for_path (filename);
-               ret = g_file_make_directory_with_parents (file, NULL, error);
-               if (!ret)
-                       goto out;
+               if (!g_file_make_directory_with_parents (file, NULL, error))
+                       return FALSE;
        }
-out:
-       if (file != NULL)
-               g_object_unref (file);
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -168,7 +165,8 @@ gcm_calibrate_get_time (void)
 const gchar *
 gcm_calibrate_get_filename_result (GcmCalibrate *calibrate)
 {
-       return calibrate->priv->filename_result;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
+       return priv->filename_result;
 }
 
 /**
@@ -177,7 +175,8 @@ gcm_calibrate_get_filename_result (GcmCalibrate *calibrate)
 const gchar *
 gcm_calibrate_get_working_path (GcmCalibrate *calibrate)
 {
-       return calibrate->priv->working_path;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
+       return priv->working_path;
 }
 
 /**
@@ -186,7 +185,8 @@ gcm_calibrate_get_working_path (GcmCalibrate *calibrate)
 const gchar *
 gcm_calibrate_get_basename (GcmCalibrate *calibrate)
 {
-       return calibrate->priv->basename;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
+       return priv->basename;
 }
 
 /**
@@ -195,7 +195,8 @@ gcm_calibrate_get_basename (GcmCalibrate *calibrate)
 guint
 gcm_calibrate_get_screen_brightness (GcmCalibrate *calibrate)
 {
-       return calibrate->priv->new_brightness;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
+       return priv->new_brightness;
 }
 
 /**
@@ -256,17 +257,15 @@ gcm_calibrate_set_from_exif (GcmCalibrate *calibrate, const gchar *filename, GEr
        const gchar *manufacturer;
        const gchar *model;
        const gchar *serial;
-       gchar *description = NULL;
-       gboolean ret;
-       GcmExif *exif;
-       GFile *file;
+       g_autofree gchar *description = NULL;
+       g_autoptr(GcmExif) exif;
+       g_autoptr(GFile) file = NULL;
 
        /* parse file */
        exif = gcm_exif_new ();
        file = g_file_new_for_path (filename);
-       ret = gcm_exif_parse (exif, file, error);
-       if (!ret)
-               goto out;
+       if (!gcm_exif_parse (exif, file, error))
+               return FALSE;
 
        /* get data */
        manufacturer = gcm_exif_get_manufacturer (exif);
@@ -285,25 +284,22 @@ gcm_calibrate_set_from_exif (GcmCalibrate *calibrate, const gchar *filename, GEr
                g_object_set (calibrate, "manufacturer", manufacturer, NULL);
        if (serial != NULL)
                g_object_set (calibrate, "serial", serial, NULL);
-
-out:
-       g_object_unref (file);
-       g_object_unref (exif);
-       g_free (description);
-       return ret;
+       return TRUE;
 }
 
 void
 gcm_calibrate_set_sensor (GcmCalibrate *calibrate, CdSensor *sensor)
 {
-       calibrate->priv->sensor = g_object_ref (sensor);
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
+       priv->sensor = g_object_ref (sensor);
 }
 
 CdSensor *
 gcm_calibrate_get_sensor (GcmCalibrate *calibrate)
 {
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        /* do not refcount */
-       return calibrate->priv->sensor;
+       return priv->sensor;
 }
 
 /**
@@ -315,7 +311,7 @@ gcm_calibrate_set_working_path (GcmCalibrate *calibrate, GError **error)
        gboolean ret = FALSE;
        gchar *timespec = NULL;
        gchar *folder = NULL;
-       GcmCalibratePrivate *priv = calibrate->priv;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
 
        /* remove old value */
        g_free (priv->working_path);
@@ -336,18 +332,19 @@ gcm_calibrate_set_working_path (GcmCalibrate *calibrate, GError **error)
 void
 gcm_calibrate_interaction (GcmCalibrate *calibrate, GtkResponseType response)
 {
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
 
        /* restore old status */
        if (response == GTK_RESPONSE_OK) {
-               if (calibrate->priv->old_title != NULL) {
+               if (priv->old_title != NULL) {
                        gcm_calibrate_set_title (calibrate,
-                                                calibrate->priv->old_title,
+                                                priv->old_title,
                                                 GCM_CALIBRATE_UI_POST_INTERACTION);
                }
-               if (calibrate->priv->old_message != NULL) {
+               if (priv->old_message != NULL) {
                        gcm_calibrate_set_message (calibrate,
-                                                  calibrate->priv->old_message,
+                                                  priv->old_message,
                                                   GCM_CALIBRATE_UI_POST_INTERACTION);
                }
 
@@ -371,23 +368,19 @@ gcm_calibrate_copy_file (const gchar *src,
                         const gchar *dest,
                         GError **error)
 {
-       gboolean ret;
-       GFile *file_src;
-       GFile *file_dest;
+       g_autoptr(GFile) file_src;
+       g_autoptr(GFile) file_dest;
 
        g_debug ("copying from %s to %s", src, dest);
        file_src = g_file_new_for_path (src);
        file_dest = g_file_new_for_path (dest);
-       ret = g_file_copy (file_src,
-                          file_dest,
-                          G_FILE_COPY_NONE,
-                          NULL,
-                          NULL,
-                          NULL,
-                          error);
-       g_object_unref (file_src);
-       g_object_unref (file_dest);
-       return ret;
+       return g_file_copy (file_src,
+                           file_dest,
+                           G_FILE_COPY_NONE,
+                           NULL,
+                           NULL,
+                           NULL,
+                           error);
 }
 
 /**
@@ -396,6 +389,7 @@ gcm_calibrate_copy_file (const gchar *src,
 void
 gcm_calibrate_interaction_attach (GcmCalibrate *calibrate)
 {
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        const gchar *filename;
        GString *message;
 
@@ -406,7 +400,7 @@ gcm_calibrate_interaction_attach (GcmCalibrate *calibrate)
 
        /* different messages with or without image */
        message = g_string_new ("");
-       filename = cd_sensor_get_metadata_item (calibrate->priv->sensor,
+       filename = cd_sensor_get_metadata_item (priv->sensor,
                                                CD_SENSOR_METADATA_IMAGE_ATTACH);
        if (filename != NULL) {
                /* TRANSLATORS: dialog message, ask user to attach device, and there's an example image */
@@ -417,7 +411,7 @@ gcm_calibrate_interaction_attach (GcmCalibrate *calibrate)
        }
 
        /* this hardware doesn't suck :) */
-       if (cd_sensor_get_kind (calibrate->priv->sensor) == CD_SENSOR_KIND_COLORHUG) {
+       if (cd_sensor_get_kind (priv->sensor) == CD_SENSOR_KIND_COLORHUG) {
                g_string_append (message, "\n\n");
                /* TRANSLATORS: dialog message, ask user to attach device */
                g_string_append (message, _("You will need to hold the device on the screen for the duration 
of the calibration."));
@@ -445,6 +439,7 @@ gcm_calibrate_interaction_attach (GcmCalibrate *calibrate)
 void
 gcm_calibrate_interaction_screen (GcmCalibrate *calibrate)
 {
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        const gchar *filename;
 
        /* TRANSLATORS: title, instrument is a hardware color calibration sensor */
@@ -453,7 +448,7 @@ gcm_calibrate_interaction_screen (GcmCalibrate *calibrate)
                                 GCM_CALIBRATE_UI_INTERACTION);
 
        /* get the image, if we have one */
-       filename = cd_sensor_get_metadata_item (calibrate->priv->sensor,
+       filename = cd_sensor_get_metadata_item (priv->sensor,
                                                CD_SENSOR_METADATA_IMAGE_CALIBRATE);
        gcm_calibrate_set_image (calibrate, filename);
        gcm_calibrate_interaction_required (calibrate, _("Continue"));
@@ -483,6 +478,7 @@ gcm_calibrate_interaction_screen (GcmCalibrate *calibrate)
 void
 gcm_calibrate_interaction_calibrate (GcmCalibrate *calibrate)
 {
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        const gchar *filename;
 
        /* TRANSLATORS: title, instrument is a hardware color calibration sensor */
@@ -494,7 +490,7 @@ gcm_calibrate_interaction_calibrate (GcmCalibrate *calibrate)
        g_debug ("blocking waiting for user input");
 
        /* get the image, if we have one */
-       filename = cd_sensor_get_metadata_item (calibrate->priv->sensor,
+       filename = cd_sensor_get_metadata_item (priv->sensor,
                                                CD_SENSOR_METADATA_IMAGE_CALIBRATE);
        gcm_calibrate_set_image (calibrate, filename);
        gcm_calibrate_interaction_required (calibrate, _("Continue"));
@@ -524,6 +520,7 @@ gcm_calibrate_interaction_calibrate (GcmCalibrate *calibrate)
 static void
 gcm_calibrate_set_brightness (GcmCalibrate *calibrate, CdDevice *device)
 {
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        const gchar *xrandr_name;
        gboolean ret;
        GError *error = NULL;
@@ -538,8 +535,8 @@ gcm_calibrate_set_brightness (GcmCalibrate *calibrate, CdDevice *device)
                return;
 
        /* set the brightness to max */
-       ret = gcm_brightness_get_percentage (calibrate->priv->brightness,
-                                            &calibrate->priv->old_brightness,
+       ret = gcm_brightness_get_percentage (priv->brightness,
+                                            &priv->old_brightness,
                                             &error);
        if (!ret) {
                g_warning ("failed to get brightness: %s",
@@ -547,9 +544,9 @@ gcm_calibrate_set_brightness (GcmCalibrate *calibrate, CdDevice *device)
                g_clear_error (&error);
        }
        /* FIXME: allow the user to set this */
-       calibrate->priv->new_brightness = 100;
-       ret = gcm_brightness_set_percentage (calibrate->priv->brightness,
-                                            calibrate->priv->new_brightness,
+       priv->new_brightness = 100;
+       ret = gcm_brightness_set_percentage (priv->brightness,
+                                            priv->new_brightness,
                                             &error);
        if (!ret) {
                g_warning ("failed to set brightness: %s",
@@ -564,32 +561,29 @@ gcm_calibrate_set_brightness (GcmCalibrate *calibrate, CdDevice *device)
 static void
 gcm_calibrate_unset_brightness (GcmCalibrate *calibrate, CdDevice *device)
 {
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        const gchar *xrandr_name;
        gboolean ret;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* is this a laptop */
        xrandr_name = cd_device_get_metadata_item (device,
                                                   CD_DEVICE_METADATA_XRANDR_NAME);
        if (xrandr_name == NULL)
                return;
-       ret = gcm_utils_output_is_lcd_internal (xrandr_name);
-       if (!ret)
+       if (!gcm_utils_output_is_lcd_internal (xrandr_name))
                return;
 
        /* never set */
-       if (calibrate->priv->old_brightness == G_MAXUINT)
+       if (priv->old_brightness == G_MAXUINT)
                return;
 
        /* reset the brightness to what it was before */
-       ret = gcm_brightness_set_percentage (calibrate->priv->brightness,
-                                            calibrate->priv->old_brightness,
+       ret = gcm_brightness_set_percentage (priv->brightness,
+                                            priv->old_brightness,
                                             &error);
-       if (!ret) {
-               g_warning ("failed to set brightness: %s",
-                          error->message);
-               g_error_free (error);
-       }
+       if (!ret)
+               g_warning ("failed to set brightness: %s",  error->message);
 }
 
 /**
@@ -608,15 +602,15 @@ gcm_calibrate_display (GcmCalibrate *calibrate,
        gchar *ti1_src_fn = NULL;
        gchar *ti3_fn = NULL;
        GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
-       GcmCalibratePrivate *priv = calibrate->priv;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
 
        /* set brightness */
        gcm_calibrate_set_brightness (calibrate, device);
 
        /* get a ti1 file suitable for the calibration */
        ti1_dest_fn = g_strdup_printf ("%s/%s.ti1",
-                                      calibrate->priv->working_path,
-                                      calibrate->priv->basename);
+                                      priv->working_path,
+                                      priv->basename);
 
        /* copy a pre-generated file into the working path */
        switch (priv->precision) {
@@ -768,24 +762,21 @@ gcm_calibrate_camera_get_reference_data (const gchar *directory, GtkWindow *wind
 static gchar *
 gcm_calibrate_get_device_for_it8_file (const gchar *filename)
 {
-       gchar *contents = NULL;
-       gchar **lines = NULL;
        gchar *device = NULL;
-       gboolean ret;
-       GError *error = NULL;
        guint i;
+       g_autofree gchar *contents = NULL;
+       g_auto(GStrv) lines = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* get contents */
-       ret = g_file_get_contents (filename, &contents, NULL, &error);
-       if (!ret) {
+       if (!g_file_get_contents (filename, &contents, NULL, &error)) {
                g_warning ("failed to get contents: %s", error->message);
-               g_error_free (error);
-               goto out;
+               return NULL;
        }
 
        /* split */
        lines = g_strsplit (contents, "\n", 15);
-       for (i=0; lines[i] != NULL; i++) {
+       for (i = 0; lines[i] != NULL; i++) {
                if (!g_str_has_prefix (lines[i], "ORIGINATOR"))
                        continue;
 
@@ -794,9 +785,6 @@ gcm_calibrate_get_device_for_it8_file (const gchar *filename)
                g_strdelimit (device, "\"", '\0');
                break;
        }
-out:
-       g_free (contents);
-       g_strfreev (lines);
        return device;
 }
 
@@ -850,12 +838,12 @@ gcm_calibrate_printer (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *win
        gchar *ti1_dest_fn = NULL;
        gchar *ti1_src_fn = NULL;
        GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
-       GcmCalibratePrivate *priv = calibrate->priv;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
 
        /* get a ti1 file suitable for the calibration */
        ti1_dest_fn = g_strdup_printf ("%s/%s.ti1",
-                                   calibrate->priv->working_path,
-                                   calibrate->priv->basename);
+                                   priv->working_path,
+                                   priv->basename);
 
        /* copy a pre-generated file into the working path */
        switch (priv->precision) {
@@ -965,7 +953,7 @@ gcm_calibrate_camera (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *wind
        GString *string;
        GtkWindow *window_tmp = NULL;
        gchar *precision = NULL;
-       GcmCalibratePrivate *priv = calibrate->priv;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
 
        string = g_string_new ("");
@@ -1129,10 +1117,11 @@ gcm_calibrate_set_title (GcmCalibrate *calibrate,
                         const gchar *title,
                         GcmCalibrateUiType ui_type)
 {
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        g_signal_emit (calibrate, signals[SIGNAL_TITLE_CHANGED], 0, title);
        if (ui_type == GCM_CALIBRATE_UI_STATUS && title != NULL) {
-               g_free (calibrate->priv->old_title);
-               calibrate->priv->old_title = g_strdup (title);
+               g_free (priv->old_title);
+               priv->old_title = g_strdup (title);
        }
 }
 
@@ -1141,10 +1130,11 @@ gcm_calibrate_set_message (GcmCalibrate *calibrate,
                           const gchar *message,
                           GcmCalibrateUiType ui_type)
 {
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        g_signal_emit (calibrate, signals[SIGNAL_MESSAGE_CHANGED], 0, message);
        if (ui_type == GCM_CALIBRATE_UI_STATUS && message != NULL) {
-               g_free (calibrate->priv->old_message);
-               calibrate->priv->old_message = g_strdup (message);
+               g_free (priv->old_message);
+               priv->old_message = g_strdup (message);
        }
 }
 
@@ -1174,7 +1164,7 @@ static void
 gcm_calibrate_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 {
        GcmCalibrate *calibrate = GCM_CALIBRATE (object);
-       GcmCalibratePrivate *priv = calibrate->priv;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
 
        switch (prop_id) {
        case PROP_REFERENCE_KIND:
@@ -1249,7 +1239,7 @@ static void
 gcm_calibrate_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 {
        GcmCalibrate *calibrate = GCM_CALIBRATE (object);
-       GcmCalibratePrivate *priv = calibrate->priv;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
 
        switch (prop_id) {
        case PROP_OUTPUT_NAME:
@@ -1462,8 +1452,6 @@ gcm_calibrate_class_init (GcmCalibrateClass *klass)
                              G_STRUCT_OFFSET (GcmCalibrateClass, interaction_required),
                              NULL, NULL, g_cclosure_marshal_VOID__STRING,
                              G_TYPE_NONE, 1, G_TYPE_STRING);
-
-       g_type_class_add_private (klass, sizeof (GcmCalibratePrivate));
 }
 
 /**
@@ -1472,16 +1460,16 @@ gcm_calibrate_class_init (GcmCalibrateClass *klass)
 static void
 gcm_calibrate_init (GcmCalibrate *calibrate)
 {
-       calibrate->priv = GCM_CALIBRATE_GET_PRIVATE (calibrate);
-       calibrate->priv->print_kind = GCM_CALIBRATE_PRINT_KIND_UNKNOWN;
-       calibrate->priv->reference_kind = GCM_CALIBRATE_REFERENCE_KIND_UNKNOWN;
-       calibrate->priv->precision = GCM_CALIBRATE_PRECISION_UNKNOWN;
-       calibrate->priv->sample_window = cd_sample_window_new ();
-       calibrate->priv->old_brightness = G_MAXUINT;
-       calibrate->priv->brightness = gcm_brightness_new ();
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
+       priv->print_kind = GCM_CALIBRATE_PRINT_KIND_UNKNOWN;
+       priv->reference_kind = GCM_CALIBRATE_REFERENCE_KIND_UNKNOWN;
+       priv->precision = GCM_CALIBRATE_PRECISION_UNKNOWN;
+       priv->sample_window = cd_sample_window_new ();
+       priv->old_brightness = G_MAXUINT;
+       priv->brightness = gcm_brightness_new ();
 
        // FIXME: this has to be per-run specific
-       calibrate->priv->working_path = g_strdup ("/tmp");
+       priv->working_path = g_strdup ("/tmp");
 }
 
 /**
@@ -1491,7 +1479,7 @@ static void
 gcm_calibrate_finalize (GObject *object)
 {
        GcmCalibrate *calibrate = GCM_CALIBRATE (object);
-       GcmCalibratePrivate *priv = calibrate->priv;
+       GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
 
        g_free (priv->filename_source);
        g_free (priv->filename_reference);
@@ -1504,9 +1492,9 @@ gcm_calibrate_finalize (GObject *object)
        g_free (priv->device);
        g_free (priv->serial);
        g_free (priv->working_path);
-       g_free (calibrate->priv->old_title);
-       g_free (calibrate->priv->old_message);
-       gtk_widget_destroy (GTK_WIDGET (calibrate->priv->sample_window));
+       g_free (priv->old_title);
+       g_free (priv->old_message);
+       gtk_widget_destroy (GTK_WIDGET (priv->sample_window));
        g_object_unref (priv->brightness);
        if (priv->sensor != NULL)
                g_object_unref (priv->sensor);
diff --git a/src/gcm-calibrate.h b/src/gcm-calibrate.h
index 3856f2c..62bc3b7 100644
--- a/src/gcm-calibrate.h
+++ b/src/gcm-calibrate.h
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2009-2012 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2009-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -28,22 +28,8 @@
 
 G_BEGIN_DECLS
 
-#define GCM_TYPE_CALIBRATE             (gcm_calibrate_get_type ())
-#define GCM_CALIBRATE(o)               (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_CALIBRATE, GcmCalibrate))
-#define GCM_CALIBRATE_CLASS(k)         (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_CALIBRATE, GcmCalibrateClass))
-#define GCM_IS_CALIBRATE(o)            (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_CALIBRATE))
-#define GCM_IS_CALIBRATE_CLASS(k)      (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_CALIBRATE))
-#define GCM_CALIBRATE_GET_CLASS(o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_CALIBRATE, 
GcmCalibrateClass))
-
-typedef struct _GcmCalibratePrivate    GcmCalibratePrivate;
-typedef struct _GcmCalibrate           GcmCalibrate;
-typedef struct _GcmCalibrateClass      GcmCalibrateClass;
-
-struct _GcmCalibrate
-{
-        GObject                         parent;
-        GcmCalibratePrivate            *priv;
-};
+#define GCM_TYPE_CALIBRATE (gcm_calibrate_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GcmCalibrate, gcm_calibrate, GCM, CALIBRATE, GObject)
 
 struct _GcmCalibrateClass
 {
diff --git a/src/gcm-cell-renderer-color.c b/src/gcm-cell-renderer-color.c
index 8c43ea8..b1b0bfd 100644
--- a/src/gcm-cell-renderer-color.c
+++ b/src/gcm-cell-renderer-color.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2011 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2011-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -63,7 +63,7 @@ static void
 gcm_cell_renderer_set_color (GcmCellRendererColor *renderer)
 {
        CdColorRGB8 rgb;
-       GdkPixbuf *pixbuf = NULL;
+       g_autoptr(GdkPixbuf) pixbuf = NULL;
        gint height = 26; /* TODO: needs to be a property */
        gint width = 400; /* TODO: needs to be a property */
        gint x, y;
@@ -106,8 +106,6 @@ out:
                cmsCloseProfile (profile_lab);
        if (xform != NULL)
                cmsDeleteTransform (xform);
-       if (pixbuf != NULL)
-               g_object_unref (pixbuf);
 }
 
 static void
diff --git a/src/gcm-cell-renderer-profile-text.c b/src/gcm-cell-renderer-profile-text.c
index f67cbb7..2513c32 100644
--- a/src/gcm-cell-renderer-profile-text.c
+++ b/src/gcm-cell-renderer-profile-text.c
@@ -63,8 +63,8 @@ gcm_cell_renderer_get_profile_text (CdProfile *profile)
 {
        CdColorspace colorspace;
        const gchar *id;
-       gchar *markup = NULL;
        GString *string;
+       g_autofree gchar *markup = NULL;
 
        if (profile == NULL) {
                /* TRANSLATORS: this is when there is no profile for the device */
@@ -111,8 +111,6 @@ out:
                 * profile is a test profile */
                g_string_prepend (string, _("Test profile: "));
        }
-
-       g_free (markup);
        return string;
 }
 
diff --git a/src/gcm-cie-widget.c b/src/gcm-cie-widget.c
index 42fbf72..d8ac5d4 100644
--- a/src/gcm-cie-widget.c
+++ b/src/gcm-cie-widget.c
@@ -771,7 +771,7 @@ gcm_cie_widget_get_min_max_tongue (GcmCieWidget *cie)
 
        /* add enough elements to the array */
        g_ptr_array_set_size (priv->tongue_buffer, 0);
-       for (i=0; i<priv->chart_height; i++) {
+       for (i = 0; i<priv->chart_height; i++) {
                item = g_new0 (GcmCieWidgetBufferItem, 1);
                g_ptr_array_add (priv->tongue_buffer, item);
        }
diff --git a/src/gcm-exif.c b/src/gcm-exif.c
index 1fd152e..08d6817 100644
--- a/src/gcm-exif.c
+++ b/src/gcm-exif.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2010-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -30,20 +30,18 @@
 
 static void     gcm_exif_finalize      (GObject     *object);
 
-#define GCM_EXIF_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_EXIF, GcmExifPrivate))
-
 /**
  * GcmExifPrivate:
  *
  * Private #GcmExif data
  **/
-struct _GcmExifPrivate
+typedef struct
 {
        gchar                           *manufacturer;
        gchar                           *model;
        gchar                           *serial;
        CdDeviceKind                     device_kind;
-};
+} GcmExifPrivate;
 
 enum {
        PROP_0,
@@ -54,7 +52,8 @@ enum {
        PROP_LAST
 };
 
-G_DEFINE_TYPE (GcmExif, gcm_exif, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GcmExif, gcm_exif, G_TYPE_OBJECT)
+#define GET_PRIVATE(o) (gcm_exif_get_instance_private (o))
 
 /**
  * gcm_exif_parse_tiff:
@@ -69,7 +68,7 @@ gcm_exif_parse_tiff (GcmExif *exif, const gchar *filename, GError **error)
        const gchar *temp = NULL;
        CdDeviceKind device_kind = CD_DEVICE_KIND_UNKNOWN;
        TIFF *tiff;
-       GcmExifPrivate *priv = exif->priv;
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
 
        /* open file */
        tiff = TIFFOpen (filename, "r");
@@ -121,7 +120,7 @@ static gboolean
 gcm_exif_parse_jpeg (GcmExif *exif, const gchar *filename, GError **error)
 {
        gboolean ret = TRUE;
-       GcmExifPrivate *priv = exif->priv;
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
        ExifData *ed = NULL;
        ExifEntry *entry;
        CdDeviceKind device_kind = CD_DEVICE_KIND_UNKNOWN;
@@ -197,11 +196,11 @@ out:
 static gboolean
 gcm_exif_parse_exiv (GcmExif *exif, const gchar *filename, GError **error)
 {
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
        gboolean ret;
        gint exit_status = 0;
-       gchar *standard_output = NULL;
-       gchar **split = NULL;
-       GcmExifPrivate *priv = exif->priv;
+       g_autofree gchar *standard_output = NULL;
+       g_auto(GStrv) split = NULL;
        const gchar *argv[] = { LIBEXECDIR "/gcm-helper-exiv",
                          filename,
                          NULL };
@@ -216,23 +215,21 @@ gcm_exif_parse_exiv (GcmExif *exif, const gchar *filename, GError **error)
                            &exit_status,
                            error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* failed to sniff */
        if (exit_status != 0) {
-               ret = FALSE;
                g_set_error (error, GCM_EXIF_ERROR, GCM_EXIF_ERROR_NO_SUPPORT,
                             "Failed to run: %s", standard_output);
-               goto out;
+               return FALSE;
        }
 
        /* get data */
        split = g_strsplit (standard_output, "\n", -1);
        if (g_strv_length (split) != 4) {
-               ret = FALSE;
                g_set_error (error, GCM_EXIF_ERROR, GCM_EXIF_ERROR_NO_SUPPORT,
                             "Unexpected output: %s", standard_output);
-               goto out;
+               return FALSE;
        }
 
        /* free old versions */
@@ -254,11 +251,7 @@ gcm_exif_parse_exiv (GcmExif *exif, const gchar *filename, GError **error)
        else
                priv->serial = NULL;
        priv->device_kind = CD_DEVICE_KIND_CAMERA;
-
-out:
-       g_free (standard_output);
-       g_strfreev (split);
-       return ret;
+       return TRUE;
 }
 #endif
 
@@ -268,9 +261,8 @@ out:
 gboolean
 gcm_exif_parse (GcmExif *exif, GFile *file, GError **error)
 {
-       gboolean ret = FALSE;
-       gchar *filename = NULL;
-       GFileInfo *info = NULL;
+       g_autofree gchar *filename = NULL;
+       g_autoptr(GFileInfo) info = NULL;
        const gchar *content_type;
 
        g_return_val_if_fail (GCM_IS_EXIF (exif), FALSE);
@@ -280,19 +272,17 @@ gcm_exif_parse (GcmExif *exif, GFile *file, GError **error)
        info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
                                  G_FILE_QUERY_INFO_NONE, NULL, error);
        if (info == NULL)
-               goto out;
+               return FALSE;;
 
        /* get EXIF data in different ways depending on content type */
        content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
        if (g_strcmp0 (content_type, "image/tiff") == 0) {
                filename = g_file_get_path (file);
-               ret = gcm_exif_parse_tiff (exif, filename, error);
-               goto out;
+               return gcm_exif_parse_tiff (exif, filename, error);
        }
        if (g_strcmp0 (content_type, "image/jpeg") == 0) {
                filename = g_file_get_path (file);
-               ret = gcm_exif_parse_jpeg (exif, filename, error);
-               goto out;
+               return gcm_exif_parse_jpeg (exif, filename, error);
        }
 
 #ifdef HAVE_EXIV
@@ -309,8 +299,7 @@ gcm_exif_parse (GcmExif *exif, GFile *file, GError **error)
            g_strcmp0 (content_type, "image/x-sigma-x3f") == 0 ||
            g_strcmp0 (content_type, "image/x-sony-arw") == 0) {
                filename = g_file_get_path (file);
-               ret = gcm_exif_parse_exiv (exif, filename, error);
-               goto out;
+               return gcm_exif_parse_exiv (exif, filename, error);
        }
 #endif
 
@@ -319,11 +308,7 @@ gcm_exif_parse (GcmExif *exif, GFile *file, GError **error)
                     GCM_EXIF_ERROR,
                     GCM_EXIF_ERROR_NO_SUPPORT,
                     "No support for %s content type", content_type);
-out:
-       g_free (filename);
-       if (info != NULL)
-               g_object_unref (info);
-       return ret;
+       return FALSE;
 }
 
 /**
@@ -332,8 +317,8 @@ out:
 const gchar *
 gcm_exif_get_manufacturer (GcmExif *exif)
 {
-       g_return_val_if_fail (GCM_IS_EXIF (exif), NULL);
-       return exif->priv->manufacturer;
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
+       return priv->manufacturer;
 }
 
 /**
@@ -342,8 +327,8 @@ gcm_exif_get_manufacturer (GcmExif *exif)
 const gchar *
 gcm_exif_get_model (GcmExif *exif)
 {
-       g_return_val_if_fail (GCM_IS_EXIF (exif), NULL);
-       return exif->priv->model;
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
+       return priv->model;
 }
 
 /**
@@ -352,8 +337,8 @@ gcm_exif_get_model (GcmExif *exif)
 const gchar *
 gcm_exif_get_serial (GcmExif *exif)
 {
-       g_return_val_if_fail (GCM_IS_EXIF (exif), NULL);
-       return exif->priv->serial;
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
+       return priv->serial;
 }
 
 /**
@@ -362,8 +347,8 @@ gcm_exif_get_serial (GcmExif *exif)
 CdDeviceKind
 gcm_exif_get_device_kind (GcmExif *exif)
 {
-       g_return_val_if_fail (GCM_IS_EXIF (exif), CD_DEVICE_KIND_UNKNOWN);
-       return exif->priv->device_kind;
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
+       return priv->device_kind;
 }
 
 /**
@@ -373,7 +358,7 @@ static void
 gcm_exif_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 {
        GcmExif *exif = GCM_EXIF (object);
-       GcmExifPrivate *priv = exif->priv;
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
 
        switch (prop_id) {
        case PROP_MANUFACTURER:
@@ -436,8 +421,6 @@ gcm_exif_class_init (GcmExifClass *klass)
                                   0, G_MAXUINT, CD_DEVICE_KIND_UNKNOWN,
                                   G_PARAM_READABLE);
        g_object_class_install_property (object_class, PROP_DEVICE_KIND, pspec);
-
-       g_type_class_add_private (klass, sizeof (GcmExifPrivate));
 }
 
 /**
@@ -446,11 +429,11 @@ gcm_exif_class_init (GcmExifClass *klass)
 static void
 gcm_exif_init (GcmExif *exif)
 {
-       exif->priv = GCM_EXIF_GET_PRIVATE (exif);
-       exif->priv->manufacturer = NULL;
-       exif->priv->model = NULL;
-       exif->priv->serial = NULL;
-       exif->priv->device_kind = CD_DEVICE_KIND_CAMERA;
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
+       priv->manufacturer = NULL;
+       priv->model = NULL;
+       priv->serial = NULL;
+       priv->device_kind = CD_DEVICE_KIND_CAMERA;
 }
 
 /**
@@ -460,7 +443,7 @@ static void
 gcm_exif_finalize (GObject *object)
 {
        GcmExif *exif = GCM_EXIF (object);
-       GcmExifPrivate *priv = exif->priv;
+       GcmExifPrivate *priv = GET_PRIVATE (exif);
 
        g_free (priv->manufacturer);
        g_free (priv->model);
diff --git a/src/gcm-exif.h b/src/gcm-exif.h
index 2df670e..60a8b7d 100644
--- a/src/gcm-exif.h
+++ b/src/gcm-exif.h
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2010-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -28,22 +28,8 @@
 
 G_BEGIN_DECLS
 
-#define GCM_TYPE_EXIF          (gcm_exif_get_type ())
-#define GCM_EXIF(o)            (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_EXIF, GcmExif))
-#define GCM_EXIF_CLASS(k)      (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_EXIF, GcmExifClass))
-#define GCM_IS_EXIF(o)         (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_EXIF))
-#define GCM_IS_EXIF_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_EXIF))
-#define GCM_EXIF_GET_CLASS(o)  (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_EXIF, GcmExifClass))
-
-typedef struct _GcmExifPrivate GcmExifPrivate;
-typedef struct _GcmExif                GcmExif;
-typedef struct _GcmExifClass   GcmExifClass;
-
-struct _GcmExif
-{
-        GObject                 parent;
-        GcmExifPrivate         *priv;
-};
+#define GCM_TYPE_EXIF (gcm_exif_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GcmExif, gcm_exif, GCM, EXIF, GObject)
 
 struct _GcmExifClass
 {
diff --git a/src/gcm-gamma-widget.c b/src/gcm-gamma-widget.c
index 1d25e00..458a142 100644
--- a/src/gcm-gamma-widget.c
+++ b/src/gcm-gamma-widget.c
@@ -210,7 +210,7 @@ gcm_gamma_widget_draw_lines (GcmGammaWidget *gama, cairo_t *cr)
        cairo_set_line_width (cr, 1);
 
        /* do horizontal lines */
-       for (i=0; i<gama->priv->chart_height; i++) {
+       for (i = 0; i<gama->priv->chart_height; i++) {
 
                /* set correct color */
                if (i%2 == 0) {
diff --git a/src/gcm-import.c b/src/gcm-import.c
index 6ccc5e4..4f57785 100644
--- a/src/gcm-import.c
+++ b/src/gcm-import.c
@@ -27,6 +27,7 @@
 #include <math.h>
 #include <locale.h>
 #include <colord.h>
+#include <stdlib.h>
 
 #include "gcm-utils.h"
 #include "gcm-debug.h"
@@ -40,9 +41,9 @@ gcm_import_show_details (GtkWindow *window,
                         const gchar *data)
 {
        gboolean ret;
-       GError *error = NULL;
-       GPtrArray *argv;
        guint xid;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GPtrArray) argv = NULL;
 
        /* spawn new viewer async and modal to this dialog */
        argv = g_ptr_array_new_with_free_func (g_free);
@@ -62,11 +63,8 @@ gcm_import_show_details (GtkWindow *window,
                             NULL,
                             &error);
 
-       if (!ret) {
+       if (!ret)
                g_warning ("failed to spawn viewer: %s", error->message);
-               g_error_free (error);
-       }
-       g_ptr_array_unref (argv);
        return ret;
 }
 
@@ -76,24 +74,23 @@ gcm_import_show_details (GtkWindow *window,
 int
 main (int argc, char **argv)
 {
-       CdClient *client = NULL;
-       CdProfile *profile_tmp = NULL;
+       g_autoptr(CdClient) client = NULL;
+       g_autoptr(CdProfile) profile_tmp = NULL;
        const gchar *copyright;
        const gchar *description;
        const gchar *title;
        const gchar *lang;
        gboolean ret;
-       gchar **files = NULL;
-       CdIcc *icc = NULL;
-       GError *error = NULL;
-       GFile *destination = NULL;
-       GFile *file = NULL;
        GOptionContext *context;
-       GString *string = NULL;
        GtkResponseType response;
        GtkWidget *image = NULL;
        GtkWidget *dialog;
-       guint retval = 1;
+       g_autoptr(CdIcc) icc = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GFile) destination = NULL;
+       g_autoptr(GFile) file = NULL;
+       g_autoptr(GString) string = NULL;
+       g_auto(GStrv) files = NULL;
 
        const GOptionEntry options[] = {
                { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
@@ -129,7 +126,7 @@ main (int argc, char **argv)
                                          GCM_STOCK_ICON);
                gtk_dialog_run (GTK_DIALOG (dialog));
                gtk_widget_destroy (dialog);
-               goto out;
+               return EXIT_FAILURE;
        }
 
        /* load profile */
@@ -152,9 +149,8 @@ main (int argc, char **argv)
                                                          _("Failed to parse file: %s"),
                                                          error->message);
                gtk_dialog_run (GTK_DIALOG (dialog));
-               g_error_free (error);
                gtk_widget_destroy (dialog);
-               goto out;
+               return EXIT_FAILURE;
        }
 
        /* get data */
@@ -192,8 +188,7 @@ main (int argc, char **argv)
        if (!ret) {
                g_warning ("failed to connect to colord: %s",
                           error->message);
-               g_error_free (error);
-               goto out;
+               return EXIT_FAILURE;
        }
 
        profile_tmp = cd_client_find_profile_by_property_sync (client,
@@ -209,8 +204,7 @@ main (int argc, char **argv)
                        g_warning ("failed to connect to profile %s: %s",
                                   cd_profile_get_object_path (profile_tmp),
                                   error->message);
-                       g_error_free (error);
-                       goto out;
+                       return EXIT_FAILURE;
                }
                /* TRANSLATORS: color profile already been installed */
                dialog = gtk_message_dialog_new (NULL,
@@ -230,7 +224,7 @@ main (int argc, char **argv)
                        goto try_harder;
                }
                gtk_widget_destroy (dialog);
-               goto out;
+               return EXIT_FAILURE;
        }
 
        /* get correct title */
@@ -276,7 +270,7 @@ try_harder:
 
        /* not the correct response */
        if (response != GTK_RESPONSE_OK)
-               goto out;
+               return EXIT_FAILURE;
 
        /* copy icc file to users profile path */
        profile_tmp = cd_client_import_profile_sync (client,
@@ -293,24 +287,9 @@ try_harder:
                gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
                gtk_dialog_run (GTK_DIALOG (dialog));
-               g_error_free (error);
                gtk_widget_destroy (dialog);
-               goto out;
+               return EXIT_FAILURE;
        }
-out:
-       if (file != NULL)
-               g_object_unref (file);
-       if (string != NULL)
-               g_string_free (string, TRUE);
-       if (icc != NULL)
-               g_object_unref (icc);
-       if (client != NULL)
-               g_object_unref (client);
-       if (profile_tmp != NULL)
-               g_object_unref (profile_tmp);
-       if (destination != NULL)
-               g_object_unref (destination);
-       g_strfreev (files);
-       return retval;
+       return EXIT_SUCCESS;
 }
 
diff --git a/src/gcm-inspect.c b/src/gcm-inspect.c
index e8d7768..06d5b43 100644
--- a/src/gcm-inspect.c
+++ b/src/gcm-inspect.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2009-2010 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2009-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -35,9 +35,9 @@
 static gboolean
 gcm_inspect_print_data_info (const gchar *title, const guint8 *data, gsize length)
 {
-       CdIcc *icc = NULL;
-       GError *error = NULL;
        gboolean ret;
+       g_autoptr(CdIcc) icc = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* parse the data */
        icc = cd_icc_new ();
@@ -46,8 +46,7 @@ gcm_inspect_print_data_info (const gchar *title, const guint8 *data, gsize lengt
                                &error);
        if (!ret) {
                g_warning ("failed to parse data: %s", error->message);
-               g_error_free (error);
-               goto out;
+               return FALSE;
        }
 
        /* print title */
@@ -58,10 +57,7 @@ gcm_inspect_print_data_info (const gchar *title, const guint8 *data, gsize lengt
 
        /* TRANSLATORS: this is the ICC profile copyright */
        g_print (" - %s %s\n", _("Copyright:"), cd_icc_get_copyright (icc, NULL, NULL));
-out:
-       if (icc != NULL)
-               g_object_unref (icc);
-       return ret;
+       return TRUE;
 }
 
 static gboolean
@@ -73,7 +69,7 @@ gcm_inspect_get_screen_protocol_version (GdkWindow *gdk_window,
        gboolean ret;
        gint length;
        gint rc;
-       guchar *data_tmp = NULL;
+       g_autofree guchar *data_tmp = NULL;
 
        /* get the value */
        gdk_error_trap_push ();
@@ -89,20 +85,18 @@ gcm_inspect_get_screen_protocol_version (GdkWindow *gdk_window,
                                &data_tmp);
        if (!ret) {
                g_set_error_literal (error, 1, 0, "failed to get property");
-               goto out;
+               return FALSE;
        }
        rc = gdk_error_trap_pop ();
        if (rc != 0) {
-               ret = FALSE;
                g_set_error (error, 1, 0, "failed to get atom: %i", rc);
-               goto out;
+               return FALSE;
        }
 
        /* was nothing found */
        if (length == 0) {
-               ret = FALSE;
                g_set_error (error, 1, 0, "icc profile atom has not been set");
-               goto out;
+               return FALSE;
        }
 
        /* set total */
@@ -110,11 +104,7 @@ gcm_inspect_get_screen_protocol_version (GdkWindow *gdk_window,
        *minor = (guint) data_tmp[0] % 100;
 
        /* success */
-       ret = TRUE;
-out:
-       if (data_tmp != NULL)
-               g_free (data_tmp);
-       return ret;
+       return TRUE;
 }
 
 static gboolean
@@ -173,12 +163,12 @@ static gboolean
 gcm_inspect_show_x11_atoms (void)
 {
        gboolean ret;
-       guint8 *data = NULL;
        gsize length = 0;
        GError *error = NULL;
        guint major = -1;
        guint minor = -1;
        GdkWindow *gdk_window;
+       g_autofree guint8 *data = NULL;
 
        /* setup object to access X */
        gdk_window = gdk_screen_get_root_window (gdk_screen_get_default ());
@@ -206,7 +196,6 @@ gcm_inspect_show_x11_atoms (void)
                /* TRANSLATORS: the root window of all the screens */
                g_print ("%s %i.%i\n", _("Root window protocol version:"), major, minor);
        }
-       g_free (data);
        return ret;
 }
 
@@ -285,22 +274,20 @@ out:
 static gboolean
 gcm_inspect_show_profile_for_window (guint xid)
 {
-       gboolean ret = FALSE;
        GDBusConnection *connection;
-       GError *error = NULL;
        const gchar *profile;
-       GVariant *args = NULL;
-       GVariant *response = NULL;
        GVariant *response_child = NULL;
-       GVariantIter *iter = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GVariant) args = NULL;
+       g_autoptr(GVariantIter) iter = NULL;
+       g_autoptr(GVariant) response = NULL;
 
        /* get a session bus connection */
        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
        if (connection == NULL) {
                /* TRANSLATORS: no DBus session bus */
                g_print ("%s %s\n", _("Failed to connect to session bus:"), error->message);
-               g_error_free (error);
-               goto out;
+               return FALSE;
        }
 
        /* execute sync method */
@@ -317,8 +304,7 @@ gcm_inspect_show_profile_for_window (guint xid)
        if (response == NULL) {
                /* TRANSLATORS: the DBus method failed */
                g_print ("%s %s\n", _("The request failed:"), error->message);
-               g_error_free (error);
-               goto out;
+               return FALSE;
        }
 
        /* print each device */
@@ -329,7 +315,7 @@ gcm_inspect_show_profile_for_window (guint xid)
        if (profile == NULL) {
                /* TRANSLATORS: no profile has been asigned to this window */
                g_print ("%s\n", _("There are no ICC profiles for this window"));
-               goto out;
+               return FALSE;
        }
 
        /* TRANSLATORS: this is a list of profiles suitable for the device */
@@ -337,15 +323,7 @@ gcm_inspect_show_profile_for_window (guint xid)
        g_print ("1.\t%s\n\t%s\n", "this is a title", profile);
 
        /* success */
-       ret = TRUE;
-out:
-       if (iter != NULL)
-               g_variant_iter_free (iter);
-       if (args != NULL)
-               g_variant_unref (args);
-       if (response != NULL)
-               g_variant_unref (response);
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -357,9 +335,9 @@ main (int argc, char **argv)
        gboolean x11 = FALSE;
        gboolean dump = FALSE;
        guint xid = 0;
-       gchar *filename = NULL;
        guint retval = 0;
        GOptionContext *context;
+       g_autofree gchar *filename = NULL;
 
        const GOptionEntry options[] = {
                { "xserver", 'x', 0, G_OPTION_ARG_NONE, &x11,
@@ -400,7 +378,6 @@ main (int argc, char **argv)
        if (xid != 0)
                gcm_inspect_show_profile_for_window (xid);
 
-       g_free (filename);
        return retval;
 }
 
diff --git a/src/gcm-picker.c b/src/gcm-picker.c
index e649b9f..5140c3f 100644
--- a/src/gcm-picker.c
+++ b/src/gcm-picker.c
@@ -94,25 +94,25 @@ gcm_picker_refresh_results (void)
        cmsHTRANSFORM transform_lab;
        cmsHTRANSFORM transform_rgb;
        gboolean ret;
-       gchar *text_ambient = NULL;
-       gchar *text_error = NULL;
-       gchar *text_lab = NULL;
-       gchar *text_rgb = NULL;
-       gchar *text_temperature = NULL;
-       gchar *text_whitepoint = NULL;
-       gchar *text_xyz = NULL;
        CdColorLab color_lab;
        CdColorRGB8 color_rgb;
        CdColorXYZ color_error;
        CdColorXYZ color_xyz;
-       GdkPixbuf *pixbuf = NULL;
        gdouble temperature = 0.0f;
        GtkImage *image;
        GtkLabel *label;
+       g_autoptr(GdkPixbuf) pixbuf = NULL;
+       g_autofree gchar *text_ambient = NULL;
+       g_autofree gchar *text_error = NULL;
+       g_autofree gchar *text_lab = NULL;
+       g_autofree gchar *text_rgb = NULL;
+       g_autofree gchar *text_temperature = NULL;
+       g_autofree gchar *text_whitepoint = NULL;
+       g_autofree gchar *text_xyz = NULL;
 
        /* nothing set yet */
        if (profile_filename == NULL)
-               goto out;
+               return;
 
        /* copy as we're modifying the value */
        cd_color_xyz_copy (&last_sample, &color_xyz);
@@ -138,17 +138,17 @@ gcm_picker_refresh_results (void)
                                            profile_rgb, TYPE_RGB_8,
                                            INTENT_PERCEPTUAL, 0);
        if (transform_rgb == NULL)
-               goto out;
+               return;
        transform_lab = cmsCreateTransform (profile_xyz, TYPE_XYZ_DBL,
                                            profile_lab, TYPE_Lab_DBL,
                                            INTENT_PERCEPTUAL, 0);
        if (transform_lab == NULL)
-               goto out;
+               return;
        transform_error = cmsCreateTransform (profile_rgb, TYPE_RGB_8,
                                              profile_xyz, TYPE_XYZ_DBL,
                                              INTENT_PERCEPTUAL, 0);
        if (transform_error == NULL)
-               goto out;
+               return;
 
        cmsDoTransform (transform_rgb, &color_xyz, &color_rgb, 1);
        cmsDoTransform (transform_lab, &color_xyz, &color_lab, 1);
@@ -230,16 +230,6 @@ gcm_picker_refresh_results (void)
 
        /* set image */
        gtk_image_set_from_pixbuf (image, pixbuf);
-out:
-       g_free (text_ambient);
-       g_free (text_error);
-       g_free (text_lab);
-       g_free (text_rgb);
-       g_free (text_temperature);
-       g_free (text_whitepoint);
-       g_free (text_xyz);
-       if (pixbuf != NULL)
-               g_object_unref (pixbuf);
 }
 
 /**
@@ -265,15 +255,11 @@ gcm_picker_got_results (void)
 static gboolean
 gcm_picker_unlock_timeout_cb (gpointer user_data)
 {
-       gboolean ret;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* unlock */
-       ret = cd_sensor_unlock_sync (sensor, NULL, &error);
-       if (!ret) {
+       if (!cd_sensor_unlock_sync (sensor, NULL, &error))
                g_warning ("failed to unlock: %s", error->message);
-               g_error_free (error);
-       }
        unlock_timer = 0;
        return FALSE;
 }
@@ -285,8 +271,8 @@ static void
 gcm_picker_measure_cb (GtkWidget *widget, gpointer data)
 {
        gboolean ret;
-       CdColorXYZ *tmp = NULL;
-       GError *error = NULL;
+       g_autoptr(CdColorXYZ) tmp = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* reset the image */
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "image_preview"));
@@ -299,8 +285,7 @@ gcm_picker_measure_cb (GtkWidget *widget, gpointer data)
                                           &error);
                if (!ret) {
                        g_warning ("failed to lock: %s", error->message);
-                       g_error_free (error);
-                       goto out;
+                       return;
                }
        }
 
@@ -317,7 +302,6 @@ gcm_picker_measure_cb (GtkWidget *widget, gpointer data)
                                         &error);
        if (tmp == NULL) {
                g_warning ("failed to get sample: %s", error->message);
-               g_clear_error (&error);
                goto out_unlock;
        }
        cd_color_xyz_copy (tmp, &last_sample);
@@ -331,7 +315,6 @@ gcm_picker_measure_cb (GtkWidget *widget, gpointer data)
                                         &error);
        if (!ret) {
                g_warning ("failed to get ambient: %s", error->message);
-               g_clear_error (&error);
                goto out_unlock;
        }
 #endif
@@ -340,9 +323,6 @@ out_unlock:
        unlock_timer = g_timeout_add_seconds (30, gcm_picker_unlock_timeout_cb, data);
        gcm_picker_refresh_results ();
        gcm_picker_got_results ();
-out:
-       if (tmp != NULL)
-               cd_color_xyz_free (tmp);
 }
 
 /**
@@ -353,14 +333,13 @@ gcm_picker_sensor_client_setup_ui (void)
 {
        gboolean ret = FALSE;
        GtkWidget *widget;
-       GPtrArray *sensors;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GPtrArray) sensors;
 
        /* no present */
        sensors = cd_client_get_sensors_sync (client, NULL, &error);
        if (sensors == NULL) {
                g_warning ("%s", error->message);
-               g_error_free (error);
                goto out;
        }
        if (sensors->len == 0) {
@@ -376,7 +355,6 @@ gcm_picker_sensor_client_setup_ui (void)
        if (!ret) {
                g_warning ("failed to connect to sensor: %s",
                           error->message);
-               g_error_free (error);
                goto out;
        }
 
@@ -400,8 +378,6 @@ gcm_picker_sensor_client_setup_ui (void)
 #endif
 
 out:
-       if (sensors != NULL)
-               g_ptr_array_unref (sensors);
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_measure"));
        gtk_widget_set_sensitive (widget, ret);
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "expander_results"));
@@ -454,15 +430,13 @@ gcm_picker_error_cb (cmsContext ContextID, cmsUInt32Number errorcode, const char
 static void
 gcm_prefs_space_combo_changed_cb (GtkWidget *widget, gpointer data)
 {
-       gboolean ret;
        GtkTreeIter iter;
        GtkTreeModel *model;
-       CdProfile *profile = NULL;
+       g_autoptr(CdProfile) profile = NULL;
 
        /* no selection */
-       ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX(widget), &iter);
-       if (!ret)
-               goto out;
+       if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX(widget), &iter))
+               return;
 
        /* get profile */
        model = gtk_combo_box_get_model (GTK_COMBO_BOX(widget));
@@ -470,15 +444,12 @@ gcm_prefs_space_combo_changed_cb (GtkWidget *widget, gpointer data)
                            GCM_PREFS_COMBO_COLUMN_PROFILE, &profile,
                            -1);
        if (profile == NULL)
-               goto out;
+               return;
 
        profile_filename = cd_profile_get_filename (profile);
        g_debug ("changed picker space %s", profile_filename);
 
        gcm_picker_refresh_results ();
-out:
-       if (profile != NULL)
-               g_object_unref (profile);
 }
 
 /**
@@ -488,13 +459,12 @@ static void
 gcm_prefs_set_combo_simple_text (GtkWidget *combo_box)
 {
        GtkCellRenderer *renderer;
-       GtkListStore *store;
+       g_autoptr(GtkListStore) store = NULL;
 
        store = gtk_list_store_new (2, G_TYPE_STRING, CD_TYPE_PROFILE);
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
                                              GCM_PREFS_COMBO_COLUMN_TEXT, GTK_SORT_ASCENDING);
        gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
-       g_object_unref (store);
 
        renderer = gtk_cell_renderer_text_new ();
        g_object_set (renderer,
@@ -545,14 +515,14 @@ gcm_prefs_setup_space_combobox (GtkWidget *widget)
        const gchar *tmp;
        gboolean has_profile = FALSE;
        gboolean has_vcgt;
-       gchar *text = NULL;
        gboolean ret;
-       GError *error = NULL;
-       GPtrArray *devices = NULL;
-       GPtrArray *profile_array = NULL;
        GtkTreeIter iter;
        GtkTreeModel *model;
        guint i;
+       g_autofree gchar *text = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GPtrArray) devices = NULL;
+       g_autoptr(GPtrArray) profile_array = NULL;
 
        /* get new list */
        profile_array = cd_client_get_profiles_sync (client,
@@ -561,12 +531,11 @@ gcm_prefs_setup_space_combobox (GtkWidget *widget)
        if (profile_array == NULL) {
                g_warning ("failed to get profiles: %s",
                           error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
 
        /* update each list */
-       for (i=0; i<profile_array->len; i++) {
+       for (i = 0; i<profile_array->len; i++) {
                profile = g_ptr_array_index (profile_array, i);
 
                /* connect to the profile */
@@ -574,8 +543,7 @@ gcm_prefs_setup_space_combobox (GtkWidget *widget)
                if (!ret) {
                        g_warning ("failed to connect to profile: %s",
                                   error->message);
-                       g_error_free (error);
-                       goto out;
+                       return;
                }
 
                /* ignore profiles from other user accounts */
@@ -609,7 +577,7 @@ gcm_prefs_setup_space_combobox (GtkWidget *widget)
                                                      CD_DEVICE_KIND_DISPLAY,
                                                      NULL,
                                                      &error);
-       for (i=0; i<devices->len; i++) {
+       for (i = 0; i<devices->len; i++) {
                device_tmp = g_ptr_array_index (devices, i);
 
                /* connect to the device */
@@ -617,8 +585,7 @@ gcm_prefs_setup_space_combobox (GtkWidget *widget)
                if (!ret) {
                        g_warning ("failed to connect to device: %s",
                                   error->message);
-                       g_error_free (error);
-                       goto out;
+                       return;
                }
 
                profile = cd_device_get_default_profile (device_tmp);
@@ -630,8 +597,7 @@ gcm_prefs_setup_space_combobox (GtkWidget *widget)
                if (!ret) {
                        g_warning ("failed to connect to profile: %s",
                                   error->message);
-                       g_error_free (error);
-                       goto out;
+                       return;
                }
 
                /* add device profile */
@@ -653,12 +619,6 @@ gcm_prefs_setup_space_combobox (GtkWidget *widget)
                gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
                gtk_widget_set_sensitive (widget, FALSE);
        }
-out:
-       if (devices != NULL)
-               g_ptr_array_unref (devices);
-       if (profile_array != NULL)
-               g_ptr_array_unref (profile_array);
-       g_free (text);
 }
 
 /**
@@ -679,10 +639,10 @@ static void
 gcm_picker_startup_cb (GApplication *application, gpointer user_data)
 {
        gboolean ret;
-       GError *error = NULL;
        GtkWidget *main_window;
        GtkWidget *widget;
        guint retval = 0;
+       g_autoptr(GError) error = NULL;
 
        /* get UI */
        builder = gtk_builder_new ();
@@ -691,8 +651,7 @@ gcm_picker_startup_cb (GApplication *application, gpointer user_data)
                                                &error);
        if (retval == 0) {
                g_warning ("failed to load ui: %s", error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
 
        main_window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_picker"));
@@ -737,8 +696,7 @@ gcm_picker_startup_cb (GApplication *application, gpointer user_data)
        if (!ret) {
                g_warning ("failed to connect to colord: %s",
                           error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
        g_signal_connect (client, "sensor-added",
                          G_CALLBACK (gcm_picker_sensor_client_changed_cb), NULL);
@@ -761,8 +719,6 @@ gcm_picker_startup_cb (GApplication *application, gpointer user_data)
 
        /* wait */
        gtk_widget_show (main_window);
-out:
-       return;
 }
 
 /**
diff --git a/src/gcm-print.c b/src/gcm-print.c
index e7925c7..4c32efd 100644
--- a/src/gcm-print.c
+++ b/src/gcm-print.c
@@ -122,9 +122,9 @@ gcm_print_draw_page_cb (GtkPrintOperation *operation, GtkPrintContext *context,
        gdouble width = 0.0f;
        gdouble height = 0.0f;
        const gchar *filename;
-       GdkPixbuf *pixbuf = NULL;
        cairo_surface_t *surface = NULL;
        gdouble scale;
+       g_autoptr(GdkPixbuf) pixbuf = NULL;
 
        /* get the size of the page in _pixels_ */
        width = gtk_print_context_get_width (context);
@@ -153,8 +153,6 @@ gcm_print_draw_page_cb (GtkPrintOperation *operation, GtkPrintContext *context,
 out:
        if (surface != NULL)
                cairo_surface_destroy (surface);
-       if (pixbuf != NULL)
-               g_object_unref (pixbuf);
 }
 
 /**
@@ -214,8 +212,8 @@ gcm_print_with_render_callback (GcmPrint *print, GtkWindow *window, GcmPrintRend
        GcmPrintPrivate *priv = print->priv;
        gboolean ret = TRUE;
        GcmPrintTask *task;
-       GtkPrintOperation *operation;
        GtkPrintOperationResult res;
+       g_autoptr(GtkPrintOperation) operation = NULL;
 
        /* create temp object */
        task = g_new0 (GcmPrintTask, 1);
@@ -282,7 +280,6 @@ out:
        if (task->error != NULL)
                g_error_free (task->error);
        g_free (task);
-       g_object_unref (operation);
        return ret;
 }
 
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index dbf12a8..4950535 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2007-2010 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2007-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -39,7 +39,7 @@
 static void
 gcm_test_brightness_func (void)
 {
-       GcmBrightness *brightness;
+       g_autoptr(GcmBrightness) brightness = NULL;
        gboolean ret;
        GError *error = NULL;
        guint orig_percentage;
@@ -65,18 +65,16 @@ gcm_test_brightness_func (void)
        ret = gcm_brightness_set_percentage (brightness, orig_percentage, &error);
        g_assert_no_error (error);
        g_assert (ret);
-
-       g_object_unref (brightness);
 }
 
 static void
 gcm_test_calibrate_func (void)
 {
-       GcmCalibrate *calibrate;
        gboolean ret;
        GError *error = NULL;
-       gchar *model;
-       gchar *manufacturer;
+       g_autoptr(GcmCalibrate) calibrate = NULL;
+       g_autofree gchar *model = NULL;
+       g_autofree gchar *manufacturer = NULL;
 
        calibrate = gcm_calibrate_new ();
        g_assert (calibrate != NULL);
@@ -93,9 +91,6 @@ gcm_test_calibrate_func (void)
                      NULL);
        g_assert_cmpstr (model, ==, "NIKON D60");
        g_assert_cmpstr (manufacturer, ==, "NIKON CORPORATION");
-       g_free (model);
-       g_free (manufacturer);
-       g_object_unref (calibrate);
 }
 
 static void
@@ -105,18 +100,18 @@ gcm_test_cie_widget_func (void)
        GtkWidget *image;
        GtkWidget *dialog;
        GtkWidget *vbox;
-       CdIcc *profile;
-       CdColorXYZ *white;
-       CdColorXYZ *red;
-       CdColorXYZ *green;
-       CdColorXYZ *blue;
        gboolean ret;
        gint response;
-       GFile *file = NULL;
        CdColorYxy white_Yxy;
        CdColorYxy red_Yxy;
        CdColorYxy green_Yxy;
        CdColorYxy blue_Yxy;
+       g_autoptr(CdColorXYZ) blue = NULL;
+       g_autoptr(CdColorXYZ) green = NULL;
+       g_autoptr(CdColorXYZ) red = NULL;
+       g_autoptr(CdColorXYZ) white = NULL;
+       g_autoptr(CdIcc) profile = NULL;
+       g_autoptr(GFile) file = NULL;
 
        widget = gcm_cie_widget_new ();
        g_assert (widget != NULL);
@@ -131,7 +126,6 @@ gcm_test_cie_widget_func (void)
                      "green", &green,
                      "blue", &blue,
                      NULL);
-       g_object_unref (file);
 
        cd_color_xyz_to_yxy (white, &white_Yxy);
        cd_color_xyz_to_yxy (red, &red_Yxy);
@@ -161,21 +155,15 @@ gcm_test_cie_widget_func (void)
        g_assert ((response == GTK_RESPONSE_YES));
 
        gtk_widget_destroy (dialog);
-
-       g_object_unref (profile);
-       cd_color_xyz_free (white);
-       cd_color_xyz_free (red);
-       cd_color_xyz_free (green);
-       cd_color_xyz_free (blue);
 }
 
 static void
 gcm_test_exif_func (void)
 {
-       GcmExif *exif;
        gboolean ret;
        GError *error = NULL;
        GFile *file;
+       g_autoptr(GcmExif) exif = NULL;
 
        exif = gcm_exif_new ();
        g_assert (exif != NULL);
@@ -219,8 +207,6 @@ gcm_test_exif_func (void)
        g_object_unref (file);
        g_assert_error (error, GCM_EXIF_ERROR, GCM_EXIF_ERROR_NO_SUPPORT);
        g_assert (!ret);
-
-       g_object_unref (exif);
 }
 
 static void
@@ -294,11 +280,11 @@ gcm_test_trc_widget_func (void)
        GtkWidget *image;
        GtkWidget *dialog;
        GtkWidget *vbox;
-       GPtrArray *clut;
-       CdIcc *profile;
        gboolean ret;
        gint response;
-       GFile *file;
+       g_autoptr(CdIcc) profile = NULL;
+    g_autoptr(GFile) file = NULL;
+       g_autoptr(GPtrArray) clut = NULL;
 
        widget = gcm_trc_widget_new ();
        g_assert (widget != NULL);
@@ -311,7 +297,6 @@ gcm_test_trc_widget_func (void)
        g_object_set (widget,
                      "data", clut,
                      NULL);
-       g_object_unref (file);
 
        /* show in a dialog as an example */
        dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, 
GTK_BUTTONS_YES_NO, "Does TRC widget match\nthe picture below?");
@@ -329,9 +314,6 @@ gcm_test_trc_widget_func (void)
        g_assert ((response == GTK_RESPONSE_YES));
 
        gtk_widget_destroy (dialog);
-
-       g_ptr_array_unref (clut);
-       g_object_unref (profile);
 }
 
 static void
@@ -340,8 +322,8 @@ gcm_test_utils_func (void)
        gboolean ret;
        gchar *text;
        gchar *filename;
-       GFile *file;
-       GFile *dest;
+       g_autoptr(GFile) file = NULL;
+       g_autoptr(GFile) dest = NULL;
 
        text = gcm_utils_linkify ("http://www.dave.org is text http://www.hughsie.com that needs to be linked 
to http://www.bbc.co.uk really");
        g_assert_cmpstr (text, ==, "<a href=\"http://www.dave.org\";>http://www.dave.org</a> is text "
@@ -354,8 +336,6 @@ gcm_test_utils_func (void)
        filename = g_file_get_path (dest);
        g_assert (g_str_has_suffix (filename, "/.local/share/icc/dave.icc"));
        g_free (filename);
-       g_object_unref (file);
-       g_object_unref (dest);
 
        ret = gcm_utils_output_is_lcd_internal ("LVDS1");
        g_assert (ret);
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 6efc89e..97c1eae 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2009-2010 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2009-2015 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -44,7 +44,7 @@ gcm_utils_linkify (const gchar *hostile_text)
        guint j = 0;
        gboolean ret;
        GString *string;
-       gchar *text;
+       g_autofree gchar *text = NULL;
 
        /* Properly escape this as some profiles 'helpfully' put markup in like:
         * "Copyright (C) 2005-2010 Kai-Uwe Behrmann <www.behrmann.name>" */
@@ -78,7 +78,6 @@ gcm_utils_linkify (const gchar *hostile_text)
                        break;
                }
        }
-       g_free (text);
        return g_string_free (string, FALSE);
 }
 
@@ -89,19 +88,18 @@ gboolean
 gcm_utils_install_package (const gchar *package_name, GtkWindow *window)
 {
        GDBusConnection *connection;
-       GVariant *args = NULL;
-       GVariant *response = NULL;
-       GVariantBuilder *builder = NULL;
-       GError *error = NULL;
-       gboolean ret = FALSE;
        guint32 xid = 0;
-       gchar **packages = NULL;
+       g_autoptr(GError) error = NULL;
+       g_auto(GStrv) packages = NULL;
+       g_autoptr(GVariant) args = NULL;
+       g_autoptr(GVariantBuilder) builder = NULL;
+       g_autoptr(GVariant) response = NULL;
 
        g_return_val_if_fail (package_name != NULL, FALSE);
 
 #ifndef HAVE_PACKAGEKIT
        g_warning ("cannot install %s: this package was not compiled with --enable-packagekit", package_name);
-       goto out;
+       return FALSE;
 #endif
 
        /* get xid of this window */
@@ -116,8 +114,7 @@ gcm_utils_install_package (const gchar *package_name, GtkWindow *window)
        if (connection == NULL) {
                /* TRANSLATORS: no DBus session bus */
                g_print ("%s %s\n", _("Failed to connect to session bus:"), error->message);
-               g_error_free (error);
-               goto out;
+               return FALSE;
        }
 
        /* create arguments */
@@ -140,21 +137,11 @@ gcm_utils_install_package (const gchar *package_name, GtkWindow *window)
        if (response == NULL) {
                /* TRANSLATORS: the DBus method failed */
                g_warning ("%s %s\n", _("The request failed:"), error->message);
-               g_error_free (error);
-               goto out;
+               return FALSE;
        }
 
        /* success */
-       ret = TRUE;
-out:
-       if (builder != NULL)
-               g_variant_builder_unref (builder);
-       if (args != NULL)
-               g_variant_unref (args);
-       if (response != NULL)
-               g_variant_unref (response);
-       g_strfreev (packages);
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -199,20 +186,15 @@ gcm_utils_output_is_lcd (const gchar *output_name)
 GFile *
 gcm_utils_get_profile_destination (GFile *file)
 {
-       gchar *basename;
-       gchar *destination;
-       GFile *dest;
+       g_autofree gchar *basename = NULL;
+       g_autofree gchar *destination = NULL;
 
        g_return_val_if_fail (file != NULL, NULL);
 
        /* get destination filename for this source file */
        basename = g_file_get_basename (file);
        destination = g_build_filename (g_get_user_data_dir (), "icc", basename, NULL);
-       dest = g_file_new_for_path (destination);
-
-       g_free (basename);
-       g_free (destination);
-       return dest;
+       return g_file_new_for_path (destination);
 }
 
 /**
@@ -235,7 +217,7 @@ gcm_utils_ptr_array_to_strv (GPtrArray *array)
 
        /* copy the array to a strv */
        value = g_new0 (gchar *, array->len + 1);
-       for (i=0; i<array->len; i++) {
+       for (i = 0; i<array->len; i++) {
                value_temp = (const gchar *) g_ptr_array_index (array, i);
                value[i] = g_strdup (value_temp);
        }
@@ -250,9 +232,8 @@ gcm_utils_ptr_array_to_strv (GPtrArray *array)
 gboolean
 gcm_gnome_help (const gchar *link_id)
 {
-       GError *error = NULL;
-       gchar *uri;
-       gboolean ret = TRUE;
+       g_autoptr(GError) error = NULL;
+       g_autofree gchar *uri = NULL;
 
        if (link_id)
                uri = g_strconcat ("help:gnome-color-manager?", link_id, NULL);
@@ -268,12 +249,9 @@ gcm_gnome_help (const gchar *link_id)
                                            GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", error->message);
                gtk_dialog_run (GTK_DIALOG(d));
                gtk_widget_destroy (d);
-               g_error_free (error);
-               ret = FALSE;
+               return FALSE;
        }
-
-       g_free (uri);
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -287,7 +265,7 @@ gcm_utils_alphanum_lcase (gchar *data)
        g_return_if_fail (data != NULL);
 
        /* replace unsafe chars, and make lowercase */
-       for (i=0; data[i] != '\0'; i++) {
+       for (i = 0; data[i] != '\0'; i++) {
                if (!g_ascii_isalnum (data[i]))
                        data[i] = '_';
                data[i] = g_ascii_tolower (data[i]);
@@ -305,7 +283,7 @@ gcm_utils_ensure_sensible_filename (gchar *data)
        g_return_if_fail (data != NULL);
 
        /* replace unsafe chars, and make lowercase */
-       for (i=0; data[i] != '\0'; i++) {
+       for (i = 0; data[i] != '\0'; i++) {
                if (data[i] != ' ' &&
                    data[i] != '-' &&
                    data[i] != '(' &&
@@ -375,7 +353,7 @@ gcm_utils_image_convert (GtkImage *image,
                         GError **error)
 {
        CdPixelFormat pixel_format;
-       CdTransform *transform = NULL;
+       g_autoptr(CdTransform) transform = NULL;
        GdkPixbuf *pixbuf;
        GdkPixbuf *original_pixbuf;
        gboolean ret = TRUE;
@@ -385,14 +363,14 @@ gcm_utils_image_convert (GtkImage *image,
        /* get pixbuf */
        pixbuf = gtk_image_get_pixbuf (image);
        if (pixbuf == NULL)
-               goto out;
+               return FALSE;
 
        /* work out the pixel format */
        pixel_format = gcm_utils_get_pixel_format (pixbuf);
        if (pixel_format == CD_PIXEL_FORMAT_UNKNOWN) {
                ret = FALSE;
                g_set_error_literal (error, 1, 0, "format not supported");
-               goto out;
+               return FALSE;
        }
 
        /* get a copy of the original image, *not* a ref */
@@ -433,14 +411,11 @@ gcm_utils_image_convert (GtkImage *image,
                                    NULL,
                                    error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* refresh */
        g_object_ref (pixbuf);
        gtk_image_set_from_pixbuf (image, pixbuf);
        g_object_unref (pixbuf);
-out:
-       if (transform != NULL)
-               g_object_unref (transform);
-       return ret;
+       return TRUE;
 }
diff --git a/src/gcm-viewer.c b/src/gcm-viewer.c
index bc28c33..4dd6079 100644
--- a/src/gcm-viewer.c
+++ b/src/gcm-viewer.c
@@ -113,25 +113,19 @@ gcm_viewer_error_dialog (GcmViewerPrivate *viewer, const gchar *title, const gch
 static void
 gcm_viewer_set_example_image (GcmViewerPrivate *viewer, GtkImage *image)
 {
-       gchar *filename;
-       gchar *path;
-       GdkPixbuf *pixbuf;
-       GError *error = NULL;
+       g_autofree gchar *filename;
+       g_autofree gchar *path = NULL;
+       g_autoptr(GdkPixbuf) pixbuf = NULL;
+       g_autoptr(GError) error = NULL;
 
        filename = g_strdup_printf ("viewer-example-%02i.png", viewer->example_index);
        path = g_build_filename (GCM_DATA, "figures", filename, NULL);
        pixbuf = gdk_pixbuf_new_from_file (path, &error);
        if (pixbuf == NULL) {
                g_warning ("failed to load %s: %s", filename, error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
        gtk_image_set_from_pixbuf (image, pixbuf);
-out:
-       g_free (filename);
-       g_free (path);
-       if (pixbuf != NULL)
-               g_object_unref (pixbuf);
 }
 
 /**
@@ -235,36 +229,30 @@ gcm_viewer_update_profile_connect_cb (GObject *source_object,
        const gchar *description;
        const gchar *filename;
        const gchar *icon_name;
-       gboolean ret;
-       gchar *sort = NULL;
-       GError *error = NULL;
        GtkTreeIter iter;
        GtkTreePath *path;
        GtkTreeSelection *selection;
        GtkWidget *widget;
        CdProfile *profile = CD_PROFILE (source_object);
        GcmViewerPrivate *viewer = (GcmViewerPrivate *) user_data;
+       g_autoptr(GError) error = NULL;
+       g_autofree gchar *sort = NULL;
 
        /* connect to the profile */
-       ret = cd_profile_connect_finish (profile,
-                                        res,
-                                        &error);
-       if (!ret) {
-               g_warning ("failed to connect to profile: %s",
-                          error->message);
-               g_error_free (error);
-               goto out;
+       if (!cd_profile_connect_finish (profile, res, &error)) {
+               g_warning ("failed to connect to profile: %s", error->message);
+               return;
        }
 
        /* ignore profiles from other user accounts */
        if (!cd_profile_has_access (profile))
-               goto out;
+               return;
 
        profile_kind = cd_profile_get_kind (profile);
        icon_name = gcm_viewer_profile_kind_to_icon_name (profile_kind);
        filename = cd_profile_get_filename (profile);
        if (filename == NULL)
-               goto out;
+               return;
        description = cd_profile_get_title (profile);
        sort = g_strdup_printf ("%s%s",
                                gcm_viewer_profile_get_sort_string (profile),
@@ -282,14 +270,11 @@ gcm_viewer_update_profile_connect_cb (GObject *source_object,
        widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "treeview_profiles"));
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
 
-       ret = gtk_tree_selection_get_selected (selection, NULL, NULL);
-       if (!ret) {
+       if (!gtk_tree_selection_get_selected (selection, NULL, NULL)) {
                path = gtk_tree_path_new_from_string ("0");
                gtk_tree_selection_select_path (selection, path);
                gtk_tree_path_free (path);
        }
-out:
-       g_free (sort);
 }
 
 /**
@@ -301,10 +286,10 @@ gcm_viewer_update_get_profiles_cb (GObject *source_object,
                                   gpointer user_data)
 {
        CdProfile *profile;
-       GError *error = NULL;
-       GPtrArray *profile_array = NULL;
        guint i;
        GcmViewerPrivate *viewer = (GcmViewerPrivate *) user_data;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GPtrArray) profile_array = NULL;
 
        g_debug ("updating profile list");
 
@@ -313,10 +298,8 @@ gcm_viewer_update_get_profiles_cb (GObject *source_object,
                                                       res,
                                                       &error);
        if (profile_array == NULL) {
-               g_warning ("failed to get profiles: %s",
-                          error->message);
-               g_error_free (error);
-               goto out;
+               g_warning ("failed to get profiles: %s", error->message);
+               return;
        }
 
        /* clear existing list */
@@ -325,16 +308,13 @@ gcm_viewer_update_get_profiles_cb (GObject *source_object,
        viewer->clearing_store = FALSE;
 
        /* update each list */
-       for (i=0; i<profile_array->len; i++) {
+       for (i = 0; i<profile_array->len; i++) {
                profile = g_ptr_array_index (profile_array, i);
                cd_profile_connect (profile,
                                    NULL,
                                    gcm_viewer_update_profile_connect_cb,
                                    viewer);
        }
-out:
-       if (profile_array != NULL)
-               g_ptr_array_unref (profile_array);
 }
 
 /**
@@ -359,16 +339,15 @@ static void
 gcm_viewer_profile_delete_cb (GtkWidget *widget, GcmViewerPrivate *viewer)
 {
        CdProfile *profile;
-       gboolean ret;
        const gchar *filename;
-       GError *error = NULL;
-       GFile *file = NULL;
        GtkResponseType response;
        GtkTreeIter iter;
        GtkTreeModel *model;
        GtkTreeSelection *selection;
        GtkWidget *dialog;
        GtkWindow *window;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GFile) file = NULL;
 
        /* ask the user to confirm */
        window = GTK_WINDOW(gtk_builder_get_object (viewer->builder, "dialog_viewer"));
@@ -384,14 +363,14 @@ gcm_viewer_profile_delete_cb (GtkWidget *widget, GcmViewerPrivate *viewer)
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        gtk_widget_destroy (dialog);
        if (response != GTK_RESPONSE_YES)
-               goto out;
+               return;
 
        /* get the selected row */
        widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "treeview_profiles"));
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
        if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
                g_debug ("no row selected");
-               goto out;
+               return;
        }
 
        /* get profile */
@@ -402,16 +381,10 @@ gcm_viewer_profile_delete_cb (GtkWidget *widget, GcmViewerPrivate *viewer)
        /* try to remove file */
        filename = cd_profile_get_filename (profile);
        file = g_file_new_for_path (filename);
-       ret = g_file_delete (file, NULL, &error);
-       if (!ret) {
+       if (!g_file_delete (file, NULL, &error)) {
                g_warning ("failed to be deleted: %s", error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
-out:
-       if (file != NULL)
-               g_object_unref (file);
-       return;
 }
 
 /**
@@ -476,9 +449,8 @@ gcm_viewer_file_chooser_get_icc_profile (GcmViewerPrivate *viewer)
 static gboolean
 gcm_viewer_profile_import_file (GcmViewerPrivate *viewer, GFile *file)
 {
-       gboolean ret = FALSE;
-       GError *error = NULL;
-       CdProfile *profile_tmp = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(CdProfile) profile_tmp = NULL;
 
        /* copy icc file to users profile path */
        profile_tmp = cd_client_import_profile_sync (viewer->client,
@@ -486,16 +458,11 @@ gcm_viewer_profile_import_file (GcmViewerPrivate *viewer, GFile *file)
        if (profile_tmp == NULL) {
                /* TRANSLATORS: could not read file */
                gcm_viewer_error_dialog (viewer, _("Failed to copy file"), error->message);
-               g_error_free (error);
-               goto out;
+               return FALSE;
        }
 
        /* success */
-       ret = TRUE;
-out:
-       if (profile_tmp != NULL)
-               g_object_unref (profile_tmp);
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -504,20 +471,17 @@ out:
 static void
 gcm_viewer_profile_import_cb (GtkWidget *widget, GcmViewerPrivate *viewer)
 {
-       GFile *file;
+       g_autoptr(GFile) file = NULL;
 
        /* get new file */
        file = gcm_viewer_file_chooser_get_icc_profile (viewer);
        if (file == NULL) {
                g_warning ("failed to get filename");
-               goto out;
+               return;
        }
 
        /* import this */
        gcm_viewer_profile_import_file (viewer, file);
-out:
-       if (file != NULL)
-               g_object_unref (file);
 }
 
 /**
@@ -543,7 +507,7 @@ gcm_viewer_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, gi
 
        /* split, as multiple drag targets are accepted */
        filenames = g_strsplit_set ((const gchar *)filename, "\r\n", -1);
-       for (i=0; filenames[i]!=NULL; i++) {
+       for (i = 0; filenames[i]!=NULL; i++) {
 
                /* blank entry */
                if (filenames[i][0] == '\0')
@@ -846,14 +810,13 @@ static gboolean
 gcm_viewer_add_metadata (GcmViewerPrivate *viewer,
                         CdProfile *profile)
 {
-       gboolean ret = FALSE;
-       GError *error = NULL;
-       GHashTable *metadata = NULL;
-       GList *keys = NULL;
        GList *l;
        GtkTreeIter iter;
        const gchar *value;
        const gchar *key;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GHashTable) metadata = NULL;
+       g_autoptr(GList) keys = NULL;
 
        /* clear existing */
        gtk_list_store_clear (viewer->liststore_metadata);
@@ -862,24 +825,21 @@ gcm_viewer_add_metadata (GcmViewerPrivate *viewer,
        metadata = cd_profile_get_metadata (profile);
        if (metadata == NULL) {
                g_warning ("failed to get metadata");
-               g_error_free (error);
-               goto out;
+               return FALSE;
        }
 
        /* add items */
        keys = g_hash_table_get_keys (metadata);
        if (keys == NULL)
-               goto out;
+               return FALSE;
        for (l = keys; l != NULL; l = l->next) {
-               ret = gcm_viewer_is_blacklisted_metadata_key (l->data);
-               if (!ret)
+               if (!gcm_viewer_is_blacklisted_metadata_key (l->data))
                        continue;
                key = gcm_viewer_get_localised_metadata_key ((gchar *) l->data);
                value = g_hash_table_lookup (metadata, l->data);
                if (value == NULL || value[0] == '\0')
                        continue;
-               g_debug ("Adding '%s', '%s'",
-                        key, value);
+               g_debug ("Adding '%s', '%s'", key, value);
                gtk_list_store_append (viewer->liststore_metadata, &iter);
                gtk_list_store_set (viewer->liststore_metadata,
                                    &iter,
@@ -889,12 +849,7 @@ gcm_viewer_add_metadata (GcmViewerPrivate *viewer,
        }
 
        /* success */
-       ret = TRUE;
-out:
-       g_list_free (keys);
-       if (metadata != NULL)
-               g_hash_table_unref (metadata);
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -965,9 +920,6 @@ gcm_viewer_set_profile (GcmViewerPrivate *viewer, CdProfile *profile)
 {
        GtkWidget *widget;
        GtkWindow *window;
-       CdIcc *icc = NULL;
-       GPtrArray *clut_trc = NULL;
-       GPtrArray *clut_vcgt = NULL;
        const gchar *profile_copyright;
        const gchar *profile_manufacturer;
        const gchar *profile_model ;
@@ -975,7 +927,6 @@ gcm_viewer_set_profile (GcmViewerPrivate *viewer, CdProfile *profile)
        const gchar *profile_title;
        gchar *temp;
        const gchar *filename;
-       gchar *size_text = NULL;
        CdProfileKind profile_kind;
        CdColorspace profile_colorspace;
        const gchar *profile_kind_text;
@@ -987,19 +938,22 @@ gcm_viewer_set_profile (GcmViewerPrivate *viewer, CdProfile *profile)
        guint filesize;
        gboolean show_section_to = FALSE;
        gboolean show_section_from = FALSE;
-       GError *error = NULL;
        gchar **warnings;
        guint i;
        CdProfileWarning warning;
        GString *str;
+       g_autofree gchar *size_text = NULL;
+       g_autoptr(CdIcc) icc = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GPtrArray) clut_trc = NULL;
+       g_autoptr(GPtrArray) clut_vcgt = NULL;
 
        /* connect to the profile */
        ret = cd_profile_connect_sync (profile, NULL, &error);
        if (!ret) {
                g_warning ("failed to connect to profile: %s",
                           error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
 
        /* set the preview widgets */
@@ -1007,8 +961,7 @@ gcm_viewer_set_profile (GcmViewerPrivate *viewer, CdProfile *profile)
        if (icc == NULL) {
                g_warning ("failed to load ICC profile: %s",
                           error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
 
        /* convert the image if required */
@@ -1248,15 +1201,6 @@ gcm_viewer_set_profile (GcmViewerPrivate *viewer, CdProfile *profile)
        gtk_widget_set_visible (widget, show_section_to);
        widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "vbox_from_srgb"));
        gtk_widget_set_visible (widget, show_section_from);
-
-out:
-       if (icc != NULL)
-               g_object_unref (icc);
-       if (clut_trc != NULL)
-               g_ptr_array_unref (clut_trc);
-       if (clut_vcgt != NULL)
-               g_ptr_array_unref (clut_vcgt);
-       g_free (size_text);
 }
 
 /**
@@ -1421,11 +1365,11 @@ gcm_viewer_show_single_profile_by_filename (GcmViewerPrivate *viewer,
 {
        CdProfile *profile;
        gboolean ret;
-       gchar *checksum = NULL;
-       gchar *data = NULL;
-       GError *error = NULL;
-       GHashTable *properties = NULL;
        gsize len;
+       g_autofree gchar *checksum = NULL;
+       g_autofree gchar *data = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GHashTable) properties = NULL;
 
        /* compute checksum */
        ret = g_file_get_contents (viewer->filename,
@@ -1438,8 +1382,7 @@ gcm_viewer_show_single_profile_by_filename (GcmViewerPrivate *viewer,
                                         _("Failed to open ICC profile"),
                                         error->message);
                g_application_release (G_APPLICATION (viewer->application));
-               g_error_free (error);
-               goto out;
+               return;
        }
        checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5,
                                                (const guchar *) data,
@@ -1471,15 +1414,9 @@ gcm_viewer_show_single_profile_by_filename (GcmViewerPrivate *viewer,
                                         _("Failed to import file"),
                                         error->message);
                g_application_release (G_APPLICATION (viewer->application));
-               g_error_free (error);
-               goto out;
+               return;
        }
        gcm_viewer_set_profile (viewer, profile);
-out:
-       g_free (data);
-       g_free (checksum);
-       if (properties != NULL)
-               g_hash_table_unref (properties);
 }
 
 /**
@@ -1489,8 +1426,8 @@ static void
 gcm_viewer_show_single_profile_by_id (GcmViewerPrivate *viewer,
                                      const gchar *id)
 {
-       CdProfile *profile;
-       GError *error = NULL;
+       g_autoptr(CdProfile) profile = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* select a specific profile only */
        profile = cd_client_find_profile_sync (viewer->client,
@@ -1501,13 +1438,9 @@ gcm_viewer_show_single_profile_by_id (GcmViewerPrivate *viewer,
                g_warning ("failed to get profile %s: %s",
                           viewer->profile_id,
                           error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
        gcm_viewer_set_profile (viewer, profile);
-out:
-       if (profile != NULL)
-               g_object_unref (profile);
 }
 
 /**
@@ -1516,14 +1449,14 @@ out:
 static void
 gcm_viewer_startup_cb (GApplication *application, GcmViewerPrivate *viewer)
 {
-       CdProfile *profile = NULL;
        gboolean ret;
-       GError *error = NULL;
        gint retval;
        GtkStyleContext *context;
        GtkTreeSelection *selection;
        GtkWidget *main_window;
        GtkWidget *widget;
+       g_autoptr(CdProfile) profile = NULL;
+       g_autoptr(GError) error = NULL;
 
        /* get UI */
        viewer->builder = gtk_builder_new ();
@@ -1531,10 +1464,8 @@ gcm_viewer_startup_cb (GApplication *application, GcmViewerPrivate *viewer)
                                                "/org/gnome/color-manager/gcm-viewer.ui",
                                                &error);
        if (retval == 0) {
-               g_warning ("failed to load ui: %s",
-                          error->message);
-               g_error_free (error);
-               goto out;
+               g_warning ("failed to load ui: %s", error->message);
+               return;
        }
 
        /* add application specific icons to search path */
@@ -1547,10 +1478,8 @@ gcm_viewer_startup_cb (GApplication *application, GcmViewerPrivate *viewer)
                                      NULL,
                                      &error);
        if (!ret) {
-               g_warning ("failed to connect to colord: %s",
-                          error->message);
-               g_error_free (error);
-               goto out;
+               g_warning ("failed to connect to colord: %s", error->message);
+               return;
        }
 
        /* create list stores */
@@ -1742,16 +1671,14 @@ gcm_viewer_startup_cb (GApplication *application, GcmViewerPrivate *viewer)
 
        /* specified an ID */
        if (viewer->profile_id != NULL) {
-               gcm_viewer_show_single_profile_by_id (viewer,
-                                                     viewer->profile_id);
-               goto out;
+               gcm_viewer_show_single_profile_by_id (viewer, viewer->profile_id);
+               return;
        }
 
        /* specified a filename */
        if (viewer->filename != NULL) {
-               gcm_viewer_show_single_profile_by_filename (viewer,
-                                                           viewer->filename);
-               goto out;
+               gcm_viewer_show_single_profile_by_filename (viewer, viewer->filename);
+               return;
        }
 
        /* do all this after the window has been set up */
@@ -1764,10 +1691,6 @@ gcm_viewer_startup_cb (GApplication *application, GcmViewerPrivate *viewer)
 
        /* update list of profiles */
        gcm_viewer_update_profile_list (viewer);
-out:
-       if (profile != NULL)
-               g_object_unref (profile);
-       return;
 }
 
 /**


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