[gnome-color-manager] Use g_autoptr and g_autofree



commit d286d8c85fb14977bc3bfb3c7e2f63e261355f88
Author: Richard Hughes <richard hughsie com>
Date:   Tue Jul 19 09:08:53 2016 +0100

    Use g_autoptr and g_autofree

 src/gcm-calibrate-argyll.c |  447 +++++++++++++++-----------------------------
 src/gcm-calibrate-main.c   |    3 +-
 src/gcm-calibrate.c        |   99 +++-------
 src/gcm-inspect.c          |    8 +-
 src/gcm-print.c            |    4 +-
 src/gcm-self-test.c        |   12 +-
 src/gcm-viewer.c           |   13 +-
 7 files changed, 198 insertions(+), 388 deletions(-)
---
diff --git a/src/gcm-calibrate-argyll.c b/src/gcm-calibrate-argyll.c
index 1f1ef4f..f2d9169 100644
--- a/src/gcm-calibrate-argyll.c
+++ b/src/gcm-calibrate-argyll.c
@@ -106,38 +106,32 @@ static gchar *
 gcm_calibrate_argyll_get_tool_filename (const gchar *command,
                                        GError **error)
 {
-       gboolean ret;
        gchar *filename;
 
        /* try the original argyllcms filename installed in /usr/local/bin */
        filename = g_strdup_printf ("/usr/local/bin/%s", command);
-       ret = g_file_test (filename, G_FILE_TEST_EXISTS);
-       if (ret)
-               goto out;
+       if (g_file_test (filename, G_FILE_TEST_EXISTS))
+               return filename;
 
        /* try the debian filename installed in /usr/bin */
        g_free (filename);
        filename = g_strdup_printf ("/usr/bin/argyll-%s", command);
-       ret = g_file_test (filename, G_FILE_TEST_EXISTS);
-       if (ret)
-               goto out;
+       if (g_file_test (filename, G_FILE_TEST_EXISTS))
+               return filename;
 
        /* try the original argyllcms filename installed in /usr/bin */
        g_free (filename);
        filename = g_strdup_printf ("/usr/bin/%s", command);
-       ret = g_file_test (filename, G_FILE_TEST_EXISTS);
-       if (ret)
-               goto out;
+       if (g_file_test (filename, G_FILE_TEST_EXISTS))
+               return filename;
 
        /* eek */
        g_free (filename);
-       filename = NULL;
        g_set_error (error,
                     GCM_CALIBRATE_ERROR,
                     GCM_CALIBRATE_ERROR_INTERNAL,
                     "failed to get filename for %s", command);
-out:
-       return filename;
+       return NULL;
 }
 
 static guint
@@ -145,12 +139,11 @@ gcm_calibrate_argyll_get_display (const gchar *output_name,
                                  GError **error)
 {
        gboolean ret = FALSE;
-       gchar *command = NULL;
+       g_autofree gchar *command = NULL;
        const gchar *data;
-       gchar *data_stderr = NULL;
-       gchar *data_stdout = NULL;
-       gchar *name;
-       gchar **split = NULL;
+       g_autofree gchar *data_stderr = NULL;
+       g_autofree gchar *data_stdout = NULL;
+       g_auto(GStrv) split = NULL;
        gint exit_status;
        guint display = G_MAXUINT;
        guint i;
@@ -159,7 +152,7 @@ gcm_calibrate_argyll_get_display (const gchar *output_name,
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("dispcal", error);
        if (command == NULL)
-               goto out;
+               return G_MAXUINT;
 
        /* execute it and capture stderr */
        argv[0] = command;
@@ -173,7 +166,7 @@ gcm_calibrate_argyll_get_display (const gchar *output_name,
                            &exit_status,
                            error);
        if (!ret)
-               goto out;
+               return G_MAXUINT;
 
        /* recent versions of dispcal switched to stderr output */
        if (data_stdout != NULL && data_stdout[0] != '\0') {
@@ -185,18 +178,19 @@ gcm_calibrate_argyll_get_display (const gchar *output_name,
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_INTERNAL,
                                     "no sensible output from dispcal");
-               goto out;
+               return G_MAXUINT;
        }
 
        /* split it into lines */
        split = g_strsplit (data, "\n", -1);
        for (i = 0; split[i] != NULL; i++) {
+               g_autofree gchar *name = NULL;
                if (g_strstr_len (split[i], -1, "XRandR 1.2 is faulty") != NULL) {
                        g_set_error_literal (error,
                                             GCM_CALIBRATE_ERROR,
                                             GCM_CALIBRATE_ERROR_INTERNAL,
                                             "failed to match display as RandR is faulty");
-                       goto out;
+                       return G_MAXUINT;
                }
                if (strlen (split[i]) < 27)
                        continue;
@@ -206,7 +200,6 @@ gcm_calibrate_argyll_get_display (const gchar *output_name,
                        display = atoi (&name[4]);
                        g_debug ("found %s mapped to %i", output_name, display);
                }
-               g_free (name);
        }
 
        /* nothing found */
@@ -215,13 +208,8 @@ gcm_calibrate_argyll_get_display (const gchar *output_name,
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_INTERNAL,
                                     "failed to match display");
-               goto out;
+               return G_MAXUINT;
        }
-out:
-       g_free (command);
-       g_free (data_stdout);
-       g_free (data_stderr);
-       g_strfreev (split);
        return display;
 }
 
@@ -277,10 +265,9 @@ gcm_calibrate_argyll_get_sensor_test_window_size (GcmCalibrateArgyll *calibrate_
 static void
 gcm_calibrate_argyll_debug_argv (const gchar *program, gchar **argv)
 {
-       gchar *join;
+       g_autofree gchar *join = NULL;
        join = g_strjoinv ("  ", argv);
        g_debug ("running %s  %s", program, join);
-       g_free (join);
 }
 
 static gboolean
@@ -320,7 +307,6 @@ gcm_calibrate_argyll_fork_command (GcmCalibrateArgyll *calibrate_argyll,
 
        /* we're running */
        priv->state = GCM_CALIBRATE_ARGYLL_STATE_RUNNING;
-out:
 #else
        g_set_error_literal (error,
                             GCM_CALIBRATE_ERROR,
@@ -337,10 +323,10 @@ gcm_calibrate_argyll_display_neutralise (GcmCalibrateArgyll *calibrate_argyll,
        gboolean ret = TRUE;
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
        gchar kind;
-       gchar *command = NULL;
-       gchar **argv = NULL;
-       GPtrArray *array = NULL;
-       gchar *basename = NULL;
+       g_autofree gchar *command = NULL;
+       g_auto(GStrv) argv = NULL;
+       g_autoptr(GPtrArray) array = NULL;
+       g_autofree gchar *basename = NULL;
        const gchar *output_name;
        guint display;
        guint target_whitepoint;
@@ -358,19 +344,15 @@ gcm_calibrate_argyll_display_neutralise (GcmCalibrateArgyll *calibrate_argyll,
 
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("dispcal", error);
-       if (command == NULL) {
-               ret = FALSE;
-               goto out;
-       }
+       if (command == NULL)
+               return FALSE;
 
        /* match up the output name with the device number defined by dispcal */
        output_name = cd_device_get_metadata_item (priv->device,
                                                   CD_DEVICE_METADATA_XRANDR_NAME);
        display = gcm_calibrate_argyll_get_display (output_name, error);
-       if (display == G_MAXUINT) {
-               ret = FALSE;
-               goto out;
-       }
+       if (display == G_MAXUINT)
+               return FALSE;
 
        /* get l-cd or c-rt */
        kind = gcm_calibrate_argyll_get_display_kind (calibrate_argyll);
@@ -410,7 +392,7 @@ gcm_calibrate_argyll_display_neutralise (GcmCalibrateArgyll *calibrate_argyll,
        /* start up the command */
        ret = gcm_calibrate_argyll_fork_command (calibrate_argyll, argv, error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* wait until finished */
        g_main_loop_run (priv->loop);
@@ -421,29 +403,20 @@ gcm_calibrate_argyll_display_neutralise (GcmCalibrateArgyll *calibrate_argyll,
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_USER_ABORT,
                                     "Calibration was cancelled");
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #ifdef HAVE_VTE
        if (priv->response == GTK_RESPONSE_REJECT) {
-               gchar *vte_text;
+               g_autofree gchar *vte_text = NULL;
                vte_text = vte_terminal_get_text (VTE_TERMINAL(priv->terminal), NULL, NULL, NULL);
                g_set_error (error,
                             GCM_CALIBRATE_ERROR,
                             GCM_CALIBRATE_ERROR_INTERNAL,
                             "Command failed to run successfully: %s", vte_text);
-               g_free (vte_text);
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #endif
-out:
-       if (array != NULL)
-               g_ptr_array_unref (array);
-       g_free (basename);
-       g_free (command);
-       g_strfreev (argv);
-       return ret;
+       return TRUE;
 }
 
 static gboolean
@@ -452,10 +425,10 @@ gcm_calibrate_argyll_display_read_chart (GcmCalibrateArgyll *calibrate_argyll,
 {
        gboolean ret = TRUE;
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-       gchar *command = NULL;
-       gchar **argv = NULL;
-       GPtrArray *array = NULL;
-       gchar *basename = NULL;
+       g_autofree gchar *command = NULL;
+       g_auto(GStrv) argv = NULL;
+       g_autoptr(GPtrArray) array = NULL;
+       g_autofree gchar *basename = NULL;
 
        /* get shared data */
        g_object_get (calibrate_argyll,
@@ -464,10 +437,8 @@ gcm_calibrate_argyll_display_read_chart (GcmCalibrateArgyll *calibrate_argyll,
 
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("chartread", error);
-       if (command == NULL) {
-               ret = FALSE;
-               goto out;
-       }
+       if (command == NULL)
+               return FALSE;
 
        /* TRANSLATORS: title, patches are specific colours used in calibration */
        gcm_calibrate_set_title (GCM_CALIBRATE (calibrate_argyll),
@@ -496,7 +467,7 @@ gcm_calibrate_argyll_display_read_chart (GcmCalibrateArgyll *calibrate_argyll,
        /* start up the command */
        ret = gcm_calibrate_argyll_fork_command (calibrate_argyll, argv, error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* wait until finished */
        g_main_loop_run (priv->loop);
@@ -507,29 +478,20 @@ gcm_calibrate_argyll_display_read_chart (GcmCalibrateArgyll *calibrate_argyll,
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_USER_ABORT,
                                     "calibration was cancelled");
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #ifdef HAVE_VTE
        if (priv->response == GTK_RESPONSE_REJECT) {
-               gchar *vte_text;
+               g_autofree gchar *vte_text = NULL;
                vte_text = vte_terminal_get_text (VTE_TERMINAL(priv->terminal), NULL, NULL, NULL);
                g_set_error (error,
                             GCM_CALIBRATE_ERROR,
                             GCM_CALIBRATE_ERROR_INTERNAL,
                             "command failed to run successfully: %s", vte_text);
-               g_free (vte_text);
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #endif
-out:
-       if (array != NULL)
-               g_ptr_array_unref (array);
-       g_free (basename);
-       g_free (command);
-       g_strfreev (argv);
-       return ret;
+       return TRUE;
 }
 
 static gboolean
@@ -539,10 +501,10 @@ gcm_calibrate_argyll_display_draw_and_measure (GcmCalibrateArgyll *calibrate_arg
        gboolean ret = TRUE;
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
        gchar kind;
-       gchar *command = NULL;
-       gchar **argv = NULL;
-       GPtrArray *array = NULL;
-       gchar *basename = NULL;
+       g_autofree gchar *command = NULL;
+       g_auto(GStrv) argv = NULL;
+       g_autoptr(GPtrArray) array = NULL;
+       g_autofree gchar *basename = NULL;
        const gchar *output_name;
        guint display;
        CdSensorKind sensor_kind;
@@ -558,19 +520,15 @@ gcm_calibrate_argyll_display_draw_and_measure (GcmCalibrateArgyll *calibrate_arg
 
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("dispread", error);
-       if (command == NULL) {
-               ret = FALSE;
-               goto out;
-       }
+       if (command == NULL)
+               return FALSE;
 
        /* match up the output name with the device number defined by dispcal */
        output_name = cd_device_get_metadata_item (priv->device,
                                                   CD_DEVICE_METADATA_XRANDR_NAME);
        display = gcm_calibrate_argyll_get_display (output_name, error);
-       if (display == G_MAXUINT) {
-               ret = FALSE;
-               goto out;
-       }
+       if (display == G_MAXUINT)
+               return FALSE;
 
        /* get l-cd or c-rt */
        kind = gcm_calibrate_argyll_get_display_kind (calibrate_argyll);
@@ -609,7 +567,7 @@ gcm_calibrate_argyll_display_draw_and_measure (GcmCalibrateArgyll *calibrate_arg
        /* start up the command */
        ret = gcm_calibrate_argyll_fork_command (calibrate_argyll, argv, error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* wait until finished */
        g_main_loop_run (priv->loop);
@@ -620,29 +578,20 @@ gcm_calibrate_argyll_display_draw_and_measure (GcmCalibrateArgyll *calibrate_arg
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_USER_ABORT,
                                     "calibration was cancelled");
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #ifdef HAVE_VTE
        if (priv->response == GTK_RESPONSE_REJECT) {
-               gchar *vte_text;
+               g_autofree gchar *vte_text = NULL;
                vte_text = vte_terminal_get_text (VTE_TERMINAL(priv->terminal), NULL, NULL, NULL);
                g_set_error (error,
                             GCM_CALIBRATE_ERROR,
                             GCM_CALIBRATE_ERROR_INTERNAL,
                             "command failed to run successfully: %s", vte_text);
-               g_free (vte_text);
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #endif
-out:
-       if (array != NULL)
-               g_ptr_array_unref (array);
-       g_free (basename);
-       g_free (command);
-       g_strfreev (argv);
-       return ret;
+       return TRUE;
 }
 
 static gboolean
@@ -651,14 +600,14 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
 {
        gboolean ret = TRUE;
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-       gchar **argv = NULL;
-       gchar *copyright = NULL;
-       gchar *description = NULL;
-       gchar *manufacturer = NULL;
-       gchar *model = NULL;
-       gchar *command = NULL;
-       gchar *basename = NULL;
-       GPtrArray *array = NULL;
+       g_auto(GStrv) argv = NULL;
+       g_autofree gchar *copyright = NULL;
+       g_autofree gchar *description = NULL;
+       g_autofree gchar *manufacturer = NULL;
+       g_autofree gchar *model = NULL;
+       g_autofree gchar *command = NULL;
+       g_autofree gchar *basename = NULL;
+       g_autoptr(GPtrArray) array = NULL;
 
        /* get shared data */
        g_object_get (calibrate_argyll,
@@ -671,10 +620,8 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
 
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("colprof", error);
-       if (command == NULL) {
-               ret = FALSE;
-               goto out;
-       }
+       if (command == NULL)
+               return FALSE;
 
        /* TRANSLATORS: title, a profile is a ICC file */
        gcm_calibrate_set_title (GCM_CALIBRATE (calibrate_argyll),
@@ -708,7 +655,7 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
        /* start up the command */
        ret = gcm_calibrate_argyll_fork_command (calibrate_argyll, argv, error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* wait until finished */
        g_main_loop_run (priv->loop);
@@ -719,8 +666,7 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_USER_ABORT,
                                     "calibration was cancelled");
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #ifdef HAVE_VTE
        if (priv->response == GTK_RESPONSE_REJECT) {
@@ -731,21 +677,10 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
                             GCM_CALIBRATE_ERROR_INTERNAL,
                             "command failed to run successfully: %s", vte_text);
                g_free (vte_text);
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #endif
-out:
-       if (array != NULL)
-               g_ptr_array_unref (array);
-       g_free (basename);
-       g_free (command);
-       g_free (copyright);
-       g_free (description);
-       g_free (manufacturer);
-       g_free (model);
-       g_strfreev (argv);
-       return ret;
+       return TRUE;
 }
 
 static const gchar *
@@ -875,11 +810,11 @@ gcm_calibrate_argyll_device_measure (GcmCalibrateArgyll *calibrate_argyll,
 {
        gboolean ret = TRUE;
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-       gchar **argv = NULL;
-       GPtrArray *array = NULL;
-       gchar *filename = NULL;
-       gchar *command = NULL;
-       gchar *basename = NULL;
+       g_auto(GStrv) argv = NULL;
+       g_autoptr(GPtrArray) array = NULL;
+       g_autofree gchar *filename = NULL;
+       g_autofree gchar *command = NULL;
+       g_autofree gchar *basename = NULL;
 
        /* get shared data */
        g_object_get (calibrate_argyll,
@@ -898,10 +833,8 @@ gcm_calibrate_argyll_device_measure (GcmCalibrateArgyll *calibrate_argyll,
 
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("scanin", error);
-       if (command == NULL) {
-               ret = FALSE;
-               goto out;
-       }
+       if (command == NULL)
+               return FALSE;
 
        /* argument array */
        array = g_ptr_array_new_with_free_func (g_free);
@@ -923,7 +856,7 @@ gcm_calibrate_argyll_device_measure (GcmCalibrateArgyll *calibrate_argyll,
        /* start up the command */
        ret = gcm_calibrate_argyll_fork_command (calibrate_argyll, argv, error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* wait until finished */
        g_main_loop_run (priv->loop);
@@ -934,30 +867,20 @@ gcm_calibrate_argyll_device_measure (GcmCalibrateArgyll *calibrate_argyll,
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_USER_ABORT,
                                     "calibration was cancelled");
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #ifdef HAVE_VTE
        if (priv->response == GTK_RESPONSE_REJECT) {
-               gchar *vte_text;
+               g_autofree gchar *vte_text = NULL;
                vte_text = vte_terminal_get_text (VTE_TERMINAL(priv->terminal), NULL, NULL, NULL);
                g_set_error (error,
                             GCM_CALIBRATE_ERROR,
                             GCM_CALIBRATE_ERROR_INTERNAL,
                             "command failed to run successfully: %s", vte_text);
-               g_free (vte_text);
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #endif
-out:
-       g_free (filename);
-       g_free (command);
-       g_free (basename);
-       if (array != NULL)
-               g_ptr_array_unref (array);
-       g_strfreev (argv);
-       return ret;
+       return TRUE;
 }
 
 static gboolean
@@ -966,14 +889,14 @@ gcm_calibrate_argyll_device_generate_profile (GcmCalibrateArgyll *calibrate_argy
 {
        gboolean ret = TRUE;
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-       gchar **argv = NULL;
-       GPtrArray *array = NULL;
-       gchar *command = NULL;
-       gchar *basename = NULL;
-       gchar *copyright = NULL;
-       gchar *description = NULL;
-       gchar *manufacturer = NULL;
-       gchar *model = NULL;
+       g_auto(GStrv) argv = NULL;
+       g_autoptr(GPtrArray) array = NULL;
+       g_autofree gchar *command = NULL;
+       g_autofree gchar *basename = NULL;
+       g_autofree gchar *copyright = NULL;
+       g_autofree gchar *description = NULL;
+       g_autofree gchar *manufacturer = NULL;
+       g_autofree gchar *model = NULL;
        GcmCalibrateReferenceKind reference_kind;
 
        /* get shared data */
@@ -988,10 +911,8 @@ gcm_calibrate_argyll_device_generate_profile (GcmCalibrateArgyll *calibrate_argy
 
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("colprof", error);
-       if (command == NULL) {
-               ret = FALSE;
-               goto out;
-       }
+       if (command == NULL)
+               return FALSE;
 
        /* TRANSLATORS: title, a profile is a ICC file */
        gcm_calibrate_set_title (GCM_CALIBRATE (calibrate_argyll),
@@ -1029,7 +950,7 @@ gcm_calibrate_argyll_device_generate_profile (GcmCalibrateArgyll *calibrate_argy
        /* start up the command */
        ret = gcm_calibrate_argyll_fork_command (calibrate_argyll, argv, error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* wait until finished */
        g_main_loop_run (priv->loop);
@@ -1040,8 +961,7 @@ gcm_calibrate_argyll_device_generate_profile (GcmCalibrateArgyll *calibrate_argy
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_USER_ABORT,
                                     "calibration was cancelled");
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #ifdef HAVE_VTE
        if (priv->response == GTK_RESPONSE_REJECT) {
@@ -1052,30 +972,18 @@ gcm_calibrate_argyll_device_generate_profile (GcmCalibrateArgyll *calibrate_argy
                             GCM_CALIBRATE_ERROR_INTERNAL,
                             "command failed to run successfully: %s", vte_text);
                g_free (vte_text);
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #endif
-out:
-       if (array != NULL)
-               g_ptr_array_unref (array);
-       g_free (copyright);
-       g_free (description);
-       g_free (manufacturer);
-       g_free (model);
-       g_free (basename);
-       g_free (command);
-       g_strfreev (argv);
-       return ret;
+       return TRUE;
 }
 
 static gboolean
 gcm_calibrate_argyll_set_filename_result (GcmCalibrateArgyll *calibrate_argyll,
                                          GError **error)
 {
-       gchar *filename = NULL;
-       gboolean ret = TRUE;
-       gchar *basename = NULL;
+       g_autofree gchar *filename = NULL;
+       g_autofree gchar *basename = NULL;
        const gchar *working_path;
 
        /* get shared data */
@@ -1086,12 +994,11 @@ gcm_calibrate_argyll_set_filename_result (GcmCalibrateArgyll *calibrate_argyll,
 
        /* we can't have finished with success */
        if (basename == NULL) {
-               ret = FALSE;
                g_set_error_literal (error,
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_INTERNAL,
                                     "profile was not generated");
-               goto out;
+               return FALSE;
        }
 
        /* get the finished icc file */
@@ -1099,22 +1006,18 @@ gcm_calibrate_argyll_set_filename_result (GcmCalibrateArgyll *calibrate_argyll,
 
        /* we never finished all the steps */
        if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
-               ret = FALSE;
                g_set_error_literal (error,
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_INTERNAL,
                                     "could not find completed profile");
-               goto out;
+               return FALSE;
        }
 
        /* success */
        g_object_set (calibrate_argyll,
                      "filename-result", filename,
                      NULL);
-out:
-       g_free (basename);
-       g_free (filename);
-       return ret;
+       return TRUE;
 }
 
 static gboolean
@@ -1126,7 +1029,7 @@ gcm_calibrate_argyll_remove_temp_files (GcmCalibrateArgyll *calibrate_argyll,
        gboolean ret;
        const gchar *exts[] = {"cal", "ti1", "ti3", "tif", NULL};
        const gchar *filenames[] = {"scanin.cht", "scanin-ref.txt", NULL};
-       gchar *basename = NULL;
+       g_autofree gchar *basename = NULL;
        const gchar *working_path;
 
        /* get shared data */
@@ -1175,7 +1078,6 @@ gcm_calibrate_argyll_display (GcmCalibrate *calibrate,
 {
        GcmCalibrateArgyll *calibrate_argyll = GCM_CALIBRATE_ARGYLL(calibrate);
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-       gboolean ret;
 
        priv->device = g_object_ref (device);
 
@@ -1200,40 +1102,34 @@ gcm_calibrate_argyll_display (GcmCalibrate *calibrate,
 }
 
        /* step 1 */
-       ret = gcm_calibrate_argyll_display_neutralise (calibrate_argyll, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_argyll_display_neutralise (calibrate_argyll, error))
+               return FALSE;
 
        /* set progress */
        gcm_calibrate_set_progress (calibrate, 30);
 
        /* step 3 */
-       ret = gcm_calibrate_argyll_display_draw_and_measure (calibrate_argyll, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_argyll_display_draw_and_measure (calibrate_argyll, error))
+               return FALSE;
 
        /* set progress */
        gcm_calibrate_set_progress (calibrate, 40);
 
        /* step 4 */
-       ret = gcm_calibrate_argyll_display_generate_profile (calibrate_argyll, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_argyll_display_generate_profile (calibrate_argyll, error))
+               return FALSE;
 
        /* set progress */
        gcm_calibrate_set_progress (calibrate, 80);
 
        /* step 5 */
-       ret = gcm_calibrate_argyll_remove_temp_files (calibrate_argyll, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_argyll_remove_temp_files (calibrate_argyll, error))
+               return FALSE;
 
        /* step 6 */
-       ret = gcm_calibrate_argyll_set_filename_result (calibrate_argyll, error);
-       if (!ret)
-               goto out;
-out:
-       return ret;
+       if (!gcm_calibrate_argyll_set_filename_result (calibrate_argyll, error))
+               return FALSE;
+       return TRUE;
 }
 
 static void
@@ -1262,7 +1158,7 @@ gcm_calibrate_argyll_interaction (GcmCalibrate *calibrate, GtkResponseType respo
                        g_main_loop_quit (priv->loop);
                        priv->state = GCM_CALIBRATE_ARGYLL_STATE_RUNNING;
                }
-               goto out;
+               return;
        }
 
        /* cancel */
@@ -1286,10 +1182,8 @@ gcm_calibrate_argyll_interaction (GcmCalibrate *calibrate, GtkResponseType respo
                /* stop loop */
                if (g_main_loop_is_running (priv->loop))
                        g_main_loop_quit (priv->loop);
-               goto out;
+               return;
        }
-out:
-       return;
 }
 
 static const gchar *
@@ -1326,10 +1220,10 @@ gcm_calibrate_argyll_printer_generate_targets (GcmCalibrateArgyll *calibrate_arg
 {
        gboolean ret = TRUE;
        GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-       gchar *command = NULL;
-       gchar **argv = NULL;
-       GPtrArray *array = NULL;
-       gchar *basename = NULL;
+       g_autofree gchar *command = NULL;
+       g_auto(GStrv) argv = NULL;
+       g_autoptr(GPtrArray) array = NULL;
+       g_autofree gchar *basename = NULL;
        CdSensorKind sensor_kind;
 
        /* get shared data */
@@ -1340,10 +1234,8 @@ gcm_calibrate_argyll_printer_generate_targets (GcmCalibrateArgyll *calibrate_arg
 
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("printtarg", error);
-       if (command == NULL) {
-               ret = FALSE;
-               goto out;
-       }
+       if (command == NULL)
+               return FALSE;
 
        /* TRANSLATORS: title, patches are specific colors used in calibration */
        gcm_calibrate_set_title (GCM_CALIBRATE (calibrate_argyll),
@@ -1388,7 +1280,7 @@ gcm_calibrate_argyll_printer_generate_targets (GcmCalibrateArgyll *calibrate_arg
        /* start up the command */
        ret = gcm_calibrate_argyll_fork_command (calibrate_argyll, argv, error);
        if (!ret)
-               goto out;
+               return FALSE;
 
        /* wait until finished */
        g_main_loop_run (priv->loop);
@@ -1399,29 +1291,20 @@ gcm_calibrate_argyll_printer_generate_targets (GcmCalibrateArgyll *calibrate_arg
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_USER_ABORT,
                                     "target generation was cancelled");
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #ifdef HAVE_VTE
        if (priv->response == GTK_RESPONSE_REJECT) {
-               gchar *vte_text;
+               g_autofree gchar *vte_text = NULL;
                vte_text = vte_terminal_get_text (VTE_TERMINAL(priv->terminal), NULL, NULL, NULL);
                g_set_error (error,
                             GCM_CALIBRATE_ERROR,
                             GCM_CALIBRATE_ERROR_INTERNAL,
                             "command failed to run successfully: %s", vte_text);
-               g_free (vte_text);
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 #endif
-out:
-       if (array != NULL)
-               g_ptr_array_unref (array);
-       g_free (basename);
-       g_free (command);
-       g_strfreev (argv);
-       return ret;
+       return TRUE;
 }
 
 static gboolean
@@ -1446,12 +1329,12 @@ gcm_calibrate_argyll_render_cb (GcmPrint *print,
                                GError **error)
 {
        gboolean ret = TRUE;
-       GPtrArray *array = NULL;
+       g_autoptr(GPtrArray) array = NULL;
        gdouble width, height;
        GtkPaperSize *paper_size;
-       GDir *dir = NULL;
+       g_autoptr(GDir) dir = NULL;
        const gchar *filename;
-       gchar *basename = NULL;
+       g_autofree gchar *basename = NULL;
        gchar *filename_tmp;
        const gchar *working_path;
 
@@ -1471,12 +1354,12 @@ gcm_calibrate_argyll_render_cb (GcmPrint *print,
                                                             height,
                                                             error);
        if (!ret)
-               goto out;
+               return NULL;
 
        /* list files */
        dir = g_dir_open (working_path, 0, error);
        if (dir == NULL)
-               goto out;
+               return NULL;
 
        /* read in each file */
        array = g_ptr_array_new_with_free_func (g_free);
@@ -1490,10 +1373,6 @@ gcm_calibrate_argyll_render_cb (GcmPrint *print,
                }
                filename = g_dir_read_name (dir);
        }
-out:
-       g_free (basename);
-       if (dir != NULL)
-               g_dir_close (dir);
        return array;
 }
 
@@ -1502,17 +1381,15 @@ gcm_calibrate_argyll_set_device_from_ti2 (GcmCalibrate *calibrate,
                                          const gchar *filename,
                                          GError **error)
 {
-       gboolean ret;
-       gchar *contents = NULL;
-       gchar *device = NULL;
+       g_autofree gchar *contents = NULL;
+       g_autofree gchar *device = NULL;
        const gchar *device_ptr = NULL;
-       gchar **lines = NULL;
+       g_auto(GStrv) lines = NULL;
        gint i;
 
        /* get the contents of the file */
-       ret = g_file_get_contents (filename, &contents, NULL, error);
-       if (!ret)
-               goto out;
+       if (!g_file_get_contents (filename, &contents, NULL, error))
+               return FALSE;
 
        /* find the data */
        lines = g_strsplit (contents, "\n", -1);
@@ -1531,8 +1408,7 @@ gcm_calibrate_argyll_set_device_from_ti2 (GcmCalibrate *calibrate,
                             GCM_CALIBRATE_ERROR,
                             GCM_CALIBRATE_ERROR_NO_DATA,
                             "cannot find TARGET_INSTRUMENT in %s", filename);
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 
        /* remove vendor prefix */
@@ -1544,11 +1420,7 @@ gcm_calibrate_argyll_set_device_from_ti2 (GcmCalibrate *calibrate,
        g_object_set (calibrate,
                      "device", device_ptr,
                      NULL);
-out:
-       g_free (device);
-       g_free (contents);
-       g_strfreev (lines);
-       return ret;
+       return TRUE;
 }
 
 static GtkPaperSize *
@@ -1767,10 +1639,8 @@ gcm_calibrate_argyll_pixbuf_remove_alpha (const GdkPixbuf *pixbuf)
        guchar *src, *dest;
 
        /* already no alpha */
-       if (!gdk_pixbuf_get_has_alpha (pixbuf)) {
-               new_pixbuf = gdk_pixbuf_copy (pixbuf);
-               goto out;
-       }
+       if (!gdk_pixbuf_get_has_alpha (pixbuf))
+               return gdk_pixbuf_copy (pixbuf);
 
        /* create new image, and copy RGB */
        new_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
@@ -1789,7 +1659,6 @@ gcm_calibrate_argyll_pixbuf_remove_alpha (const GdkPixbuf *pixbuf)
                        dest += 3;
                }
        }
-out:
        return new_pixbuf;
 }
 
@@ -1845,7 +1714,6 @@ gcm_calibrate_argyll_device (GcmCalibrate *calibrate,
                             GError **error)
 {
        GcmCalibrateArgyll *calibrate_argyll = GCM_CALIBRATE_ARGYLL(calibrate);
-       gboolean ret;
 
        /* TRANSLATORS: title, instrument refers to a calibration device */
        gcm_calibrate_set_title (GCM_CALIBRATE (calibrate_argyll),
@@ -1859,48 +1727,41 @@ gcm_calibrate_argyll_device (GcmCalibrate *calibrate,
 
 
        /* step 1 */
-       ret = gcm_calibrate_argyll_device_copy (calibrate_argyll, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_argyll_device_copy (calibrate_argyll, error))
+               return FALSE;
 
        /* step 1.5 */
-       ret = gcm_calibrate_argyll_check_and_remove_alpha (calibrate_argyll, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_argyll_check_and_remove_alpha (calibrate_argyll, error))
+               return FALSE;
 
        /* set progress */
        gcm_calibrate_set_progress (calibrate, 10);
 
        /* step 2 */
-       ret = gcm_calibrate_argyll_device_measure (calibrate_argyll, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_argyll_device_measure (calibrate_argyll, error))
+               return FALSE;
 
        /* set progress */
        gcm_calibrate_set_progress (calibrate, 70);
 
        /* step 3 */
-       ret = gcm_calibrate_argyll_device_generate_profile (calibrate_argyll, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_argyll_device_generate_profile (calibrate_argyll, error))
+               return FALSE;
 
        /* set progress */
        gcm_calibrate_set_progress (calibrate, 80);
 
        /* step 4 */
-       ret = gcm_calibrate_argyll_remove_temp_files (calibrate_argyll, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_argyll_remove_temp_files (calibrate_argyll, error))
+               return FALSE;
 
        /* set progress */
        gcm_calibrate_set_progress (calibrate, 90);
 
        /* step 5 */
-       ret = gcm_calibrate_argyll_set_filename_result (calibrate_argyll, error);
-       if (!ret)
-               goto out;
-out:
-       return ret;
+       if (!gcm_calibrate_argyll_set_filename_result (calibrate_argyll, error))
+               return FALSE;
+       return TRUE;
 }
 
 #ifdef HAVE_VTE
@@ -1949,7 +1810,7 @@ gcm_calibrate_argyll_interaction_attach (GcmCalibrateArgyll *calibrate_argyll)
                                                           (GSourceFunc) gcm_calibrate_argyll_timeout_cb,
                                                           calibrate_argyll);
                g_source_set_name_by_id (priv->keypress_id, "[GcmCalibrateArgyll] keypress faker");
-               goto out;
+               return;
        }
 
        /* tell the user to attach the sensor */
@@ -1962,8 +1823,6 @@ gcm_calibrate_argyll_interaction_attach (GcmCalibrateArgyll *calibrate_argyll)
 
        /* save as we know the device is on the screen now */
        priv->already_on_window = TRUE;
-out:
-       return;
 }
 
 static void
diff --git a/src/gcm-calibrate-main.c b/src/gcm-calibrate-main.c
index a14ac58..c75d7db 100644
--- a/src/gcm-calibrate-main.c
+++ b/src/gcm-calibrate-main.c
@@ -1711,7 +1711,7 @@ gcm_calib_setup_page_profile_title (GcmCalibratePriv *priv)
        GtkWidget *vbox;
        GtkWidget *content;
        GtkWidget *widget;
-       gchar *tmp = NULL;
+       g_autofree gchar *tmp = NULL;
        GtkAssistant *assistant = GTK_ASSISTANT (priv->main_window);
 
        /* TRANSLATORS: this is the page title */
@@ -1733,7 +1733,6 @@ gcm_calib_setup_page_profile_title (GcmCalibratePriv *priv)
                      "description", &tmp,
                      NULL);
        gtk_entry_set_text (GTK_ENTRY (widget), tmp);
-       g_free (tmp);
 
        /* watch for changes */
        g_signal_connect (GTK_EDITABLE (widget), "changed",
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 620b0fc..4ab489a 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -179,12 +179,12 @@ gcm_calibrate_get_screen_brightness (GcmCalibrate *calibrate)
 static void
 gcm_calibrate_set_basename (GcmCalibrate *calibrate)
 {
-       gchar *serial = NULL;
-       gchar *manufacturer = NULL;
-       gchar *model = NULL;
-       gchar *timespec = NULL;
+       g_autofree gchar *serial = NULL;
+       g_autofree gchar *manufacturer = NULL;
+       g_autofree gchar *model = NULL;
+       g_autofree gchar *timespec = NULL;
        GDate *date = NULL;
-       GString *basename;
+       g_autoptr(GString) basename = NULL;
 
        /* get device properties */
        g_object_get (calibrate,
@@ -215,11 +215,6 @@ gcm_calibrate_set_basename (GcmCalibrate *calibrate)
        g_object_set (calibrate, "basename", basename->str, NULL);
 
        g_date_free (date);
-       g_free (serial);
-       g_free (manufacturer);
-       g_free (model);
-       g_free (timespec);
-       g_string_free (basename, TRUE);
 }
 
 gboolean
@@ -276,9 +271,8 @@ gcm_calibrate_get_sensor (GcmCalibrate *calibrate)
 static gboolean
 gcm_calibrate_set_working_path (GcmCalibrate *calibrate, GError **error)
 {
-       gboolean ret = FALSE;
-       gchar *timespec = NULL;
-       gchar *folder = NULL;
+       g_autofree gchar *timespec = NULL;
+       g_autofree gchar *folder = NULL;
        GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
 
        /* remove old value */
@@ -288,10 +282,7 @@ gcm_calibrate_set_working_path (GcmCalibrate *calibrate, GError **error)
        timespec = gcm_calibrate_get_time ();
        folder = g_strjoin (" - ", priv->basename, timespec, NULL);
        priv->working_path = g_build_filename (g_get_user_config_dir (), "gnome-color-manager", 
"calibration", folder, NULL);
-       ret = gcm_calibrate_mkdir_with_parents (priv->working_path, error);
-       g_free (timespec);
-       g_free (folder);
-       return ret;
+       return gcm_calibrate_mkdir_with_parents (priv->working_path, error);
 }
 
 void
@@ -350,7 +341,7 @@ gcm_calibrate_interaction_attach (GcmCalibrate *calibrate)
 {
        GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        const gchar *filename;
-       GString *message;
+       g_autoptr(GString) message = NULL;
 
        /* TRANSLATORS: title, instrument is a hardware color calibration sensor */
        gcm_calibrate_set_title (calibrate,
@@ -388,8 +379,6 @@ gcm_calibrate_interaction_attach (GcmCalibrate *calibrate)
                         /* TRANSLATORS: this is the application name for libcanberra */
                         CA_PROP_APPLICATION_NAME, _("GNOME Color Manager"),
                         CA_PROP_EVENT_DESCRIPTION, "interaction required", NULL);
-
-       g_string_free (message, TRUE);
 }
 
 void
@@ -473,7 +462,7 @@ gcm_calibrate_set_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,
@@ -501,7 +490,6 @@ gcm_calibrate_set_brightness (GcmCalibrate *calibrate, CdDevice *device)
        if (!ret) {
                g_warning ("failed to set brightness: %s",
                           error->message);
-               g_error_free (error);
        }
 }
 
@@ -541,10 +529,10 @@ gcm_calibrate_display (GcmCalibrate *calibrate,
 {
        const gchar *filename_tmp;
        gboolean ret = TRUE;
-       gchar *cal_fn = NULL;
-       gchar *ti1_dest_fn = NULL;
-       gchar *ti1_src_fn = NULL;
-       gchar *ti3_fn = NULL;
+       g_autofree gchar *cal_fn = NULL;
+       g_autofree gchar *ti1_dest_fn = NULL;
+       g_autofree gchar *ti1_src_fn = NULL;
+       g_autofree gchar *ti3_fn = NULL;
        GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
        GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
 
@@ -592,10 +580,6 @@ gcm_calibrate_display (GcmCalibrate *calibrate,
 out:
        /* unset brightness */
        gcm_calibrate_unset_brightness (calibrate, device);
-       g_free (cal_fn);
-       g_free (ti1_src_fn);
-       g_free (ti1_dest_fn);
-       g_free (ti3_fn);
        return ret;
 }
 
@@ -727,7 +711,7 @@ static gchar *
 gcm_calibrate_file_chooser_get_working_path (GcmCalibrate *calibrate, GtkWindow *window)
 {
        GtkWidget *dialog;
-       gchar *current_folder;
+       g_autofree gchar *current_folder = NULL;
        gchar *working_path = NULL;
 
        /* start in the correct place */
@@ -752,20 +736,18 @@ gcm_calibrate_file_chooser_get_working_path (GcmCalibrate *calibrate, GtkWindow
        gtk_widget_destroy (dialog);
 
        /* or NULL for missing */
-       g_free (current_folder);
        return working_path;
 }
 
 static gboolean
 gcm_calibrate_printer (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *window, GError **error)
 {
-       gboolean ret = FALSE;
        gchar *ptr;
        GtkWindow *window_tmp = NULL;
-       gchar *precision = NULL;
+       g_autofree gchar *precision = NULL;
        const gchar *filename_tmp;
-       gchar *ti1_dest_fn = NULL;
-       gchar *ti1_src_fn = NULL;
+       g_autofree gchar *ti1_dest_fn = NULL;
+       g_autofree gchar *ti1_src_fn = NULL;
        GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
        GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
 
@@ -789,9 +771,8 @@ gcm_calibrate_printer (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *win
                g_assert_not_reached ();
        }
        ti1_src_fn = g_build_filename (GCM_DATA, "ti1", filename_tmp, NULL);
-       ret = gcm_calibrate_copy_file (ti1_src_fn, ti1_dest_fn, error);
-       if (!ret)
-               goto out;
+       if (!gcm_calibrate_copy_file (ti1_src_fn, ti1_dest_fn, error))
+               return FALSE;
 
        /* copy */
        if (priv->print_kind == GCM_CALIBRATE_PRINT_KIND_ANALYZE) {
@@ -807,8 +788,7 @@ gcm_calibrate_printer (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *win
                                             GCM_CALIBRATE_ERROR,
                                             GCM_CALIBRATE_ERROR_USER_ABORT,
                                             "user did not choose folder");
-                       ret = FALSE;
-                       goto out;
+                       return FALSE;
                }
 
                /* reprogram the basename */
@@ -827,16 +807,11 @@ gcm_calibrate_printer (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *win
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_INTERNAL,
                                     "no klass support");
-               goto out;
+               return FALSE;
        }
 
        /* proxy */
-       ret = klass->calibrate_printer (calibrate, device, priv->sensor, window, error);
-out:
-       g_free (ti1_src_fn);
-       g_free (ti1_dest_fn);
-       g_free (precision);
-       return ret;
+       return klass->calibrate_printer (calibrate, device, priv->sensor, window, error);
 }
 
 gboolean
@@ -865,14 +840,14 @@ gcm_calibrate_camera (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *wind
 {
        gboolean ret = FALSE;
        gboolean has_shared_targets = TRUE;
-       gchar *reference_image = NULL;
-       gchar *reference_data = NULL;
-       gchar *device_str = NULL;
+       g_autofree gchar *reference_image = NULL;
+       g_autofree gchar *reference_data = NULL;
+       g_autofree gchar *device_str = NULL;
        const gchar *directory;
        const gchar *tmp;
-       GString *string;
+       g_autoptr(GString) string = NULL;
        GtkWindow *window_tmp = NULL;
-       gchar *precision = NULL;
+       g_autofree gchar *precision = NULL;
        GcmCalibratePrivate *priv = GET_PRIVATE (calibrate);
        GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
 
@@ -886,8 +861,7 @@ gcm_calibrate_camera (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *wind
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_USER_ABORT,
                                     "could not get calibration target image");
-               ret = FALSE;
-               goto out;
+               return FALSE;
        }
 
        /* use the exif data if there is any present */
@@ -912,8 +886,7 @@ gcm_calibrate_camera (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *wind
                                             GCM_CALIBRATE_ERROR,
                                             GCM_CALIBRATE_ERROR_USER_ABORT,
                                             "could not get reference target");
-                       ret = FALSE;
-                       goto out;
+                       return FALSE;
                }
        }
 
@@ -935,19 +908,11 @@ gcm_calibrate_camera (GcmCalibrate *calibrate, CdDevice *device, GtkWindow *wind
                                     GCM_CALIBRATE_ERROR,
                                     GCM_CALIBRATE_ERROR_INTERNAL,
                                     "no klass support");
-               goto out;
+               return FALSE;
        }
 
        /* proxy */
-       ret = klass->calibrate_device (calibrate, device, priv->sensor, window, error);
-out:
-       if (string != NULL)
-               g_string_free (string, TRUE);
-       g_free (precision);
-       g_free (device_str);
-       g_free (reference_image);
-       g_free (reference_data);
-       return ret;
+       return klass->calibrate_device (calibrate, device, priv->sensor, window, error);
 }
 
 gboolean
diff --git a/src/gcm-inspect.c b/src/gcm-inspect.c
index 52db54a..aad63b2 100644
--- a/src/gcm-inspect.c
+++ b/src/gcm-inspect.c
@@ -158,7 +158,7 @@ gcm_inspect_show_x11_atoms (void)
 {
        gboolean ret;
        gsize length = 0;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
        guint major = -1;
        guint minor = -1;
        GdkWindow *gdk_window;
@@ -171,7 +171,6 @@ gcm_inspect_show_x11_atoms (void)
        ret = gcm_inspect_get_screen_profile_data (gdk_window, &data, &length, &error);
        if (!ret) {
                g_warning ("failed to get XServer profile data: %s", error->message);
-               g_error_free (error);
                /* non-fatal */
                error = NULL;
        } else {
@@ -183,7 +182,6 @@ gcm_inspect_show_x11_atoms (void)
        ret = gcm_inspect_get_screen_protocol_version (gdk_window, &major, &minor, &error);
        if (!ret) {
                g_warning ("failed to get XServer protocol version: %s", error->message);
-               g_error_free (error);
                /* non-fatal */
                error = NULL;
        } else {
@@ -200,7 +198,7 @@ gcm_inspect_show_profiles_for_file (const gchar *filename)
        const gchar *description;
        guint i = 0;
        GDBusConnection *connection;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
        GVariant *args = NULL;
        GVariant *response = NULL;
        GVariantIter *iter = NULL;
@@ -210,7 +208,6 @@ gcm_inspect_show_profiles_for_file (const gchar *filename)
        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;
        }
 
@@ -228,7 +225,6 @@ gcm_inspect_show_profiles_for_file (const gchar *filename)
        if (response == NULL) {
                /* TRANSLATORS: the DBus method failed */
                g_print ("%s %s\n", _("The request failed:"), error->message);
-               g_error_free (error);
                goto out;
        }
 
diff --git a/src/gcm-print.c b/src/gcm-print.c
index dbc34d0..934bc2d 100644
--- a/src/gcm-print.c
+++ b/src/gcm-print.c
@@ -92,14 +92,12 @@ gcm_print_begin_print_cb (GtkPrintOperation *operation, GtkPrintContext *context
        task->filenames = task->render_callback (task->print, page_setup, task->user_data, &task->error);
        if (task->filenames == NULL) {
                gtk_print_operation_cancel (operation);
-               goto out;
+               return;
        }
 
        /* setting the page count */
        g_debug ("setting %i pages", task->filenames->len);
        gtk_print_operation_set_n_pages (operation, task->filenames->len);
-out:
-       return;
 }
 
 static void
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 4950535..25e70bb 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -41,7 +41,7 @@ gcm_test_brightness_func (void)
 {
        g_autoptr(GcmBrightness) brightness = NULL;
        gboolean ret;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
        guint orig_percentage;
        guint percentage;
 
@@ -71,7 +71,7 @@ static void
 gcm_test_calibrate_func (void)
 {
        gboolean ret;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
        g_autoptr(GcmCalibrate) calibrate = NULL;
        g_autofree gchar *model = NULL;
        g_autofree gchar *manufacturer = NULL;
@@ -161,7 +161,7 @@ static void
 gcm_test_exif_func (void)
 {
        gboolean ret;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
        GFile *file;
        g_autoptr(GcmExif) exif = NULL;
 
@@ -261,16 +261,14 @@ static void
 gcm_test_print_func (void)
 {
        gboolean ret;
-       GError *error = NULL;
-       GcmPrint *print;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GcmPrint) print = NULL;
 
        print = gcm_print_new ();
 
        ret = gcm_print_with_render_callback (print, NULL, gcm_print_test_render_cb, NULL, &error);
        g_assert_no_error (error);
        g_assert (ret);
-
-       g_object_unref (print);
 }
 
 static void
diff --git a/src/gcm-viewer.c b/src/gcm-viewer.c
index 70282de..5f23a8d 100644
--- a/src/gcm-viewer.c
+++ b/src/gcm-viewer.c
@@ -449,8 +449,7 @@ static void
 gcm_viewer_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, gint x, gint y, 
GtkSelectionData *data, guint _time, GcmViewerPrivate *viewer)
 {
        const guchar *filename;
-       gchar **filenames = NULL;
-       GFile *file = NULL;
+       g_auto(GStrv) filenames = NULL;
        guint i;
        gboolean ret;
        gboolean success = FALSE;
@@ -466,6 +465,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++) {
+               g_autoptr(GFile) file = NULL;
 
                /* blank entry */
                if (filenames[i][0] == '\0')
@@ -478,13 +478,10 @@ gcm_viewer_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, gi
                ret = gcm_viewer_profile_import_file (viewer, file);
                if (ret)
                        success = TRUE;
-
-               g_object_unref (file);
        }
 
 out:
        gtk_drag_finish (context, success, FALSE, _time);
-       g_strfreev (filenames);
 }
 
 static void
@@ -1143,7 +1140,7 @@ gcm_viewer_profiles_treeview_clicked_cb (GtkTreeSelection *selection,
 {
        GtkTreeModel *model;
        GtkTreeIter iter;
-       CdProfile *profile;
+       g_autoptr(CdProfile) profile = NULL;
 
        /* ignore */
        if (viewer->clearing_store)
@@ -1160,7 +1157,6 @@ gcm_viewer_profiles_treeview_clicked_cb (GtkTreeSelection *selection,
                            GCM_PROFILES_COLUMN_PROFILE, &profile,
                            -1);
        gcm_viewer_set_profile (viewer, profile);
-       g_object_unref (profile);
 }
 
 static void
@@ -1610,7 +1606,7 @@ main (int argc, char **argv)
        guint xid = 0;
        int status = 0;
        gboolean ret;
-       GError *error = NULL;
+       g_autoptr(GError) error = NULL;
 
        const GOptionEntry options[] = {
                { "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
@@ -1640,7 +1636,6 @@ main (int argc, char **argv)
        ret = g_option_context_parse (context, &argc, &argv, &error);
        if (!ret) {
                g_warning ("failed to parse options: %s", error->message);
-               g_error_free (error);
        }
        g_option_context_free (context);
 



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