summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-11-06 22:37:19 +0000
committerRichard Hughes <richard@hughsie.com>2014-11-06 22:47:30 +0000
commit942898d8df0403c3b4753821d47d583d55c77432 (patch)
treea4e714f5d8a6877bf5333c80d88cc6361e9425ed
parentcf8a0d8a0844c54e188c363409c2be04cb0b9c19 (diff)
downloadcolord-942898d8df0403c3b4753821d47d583d55c77432.tar.gz
Use _cleanup_free() in the client tools
-rw-r--r--client/cd-create-profile.c229
-rw-r--r--client/cd-find-broken.c32
-rw-r--r--client/cd-fix-profile.c189
-rw-r--r--client/cd-iccdump.c32
-rw-r--r--client/cd-it8.c93
-rw-r--r--client/cd-util.c863
6 files changed, 455 insertions, 983 deletions
diff --git a/client/cd-create-profile.c b/client/cd-create-profile.c
index 60587ce..1251518 100644
--- a/client/cd-create-profile.c
+++ b/client/cd-create-profile.c
@@ -29,6 +29,8 @@
#include <math.h>
#include <colord-private.h>
+#include "cd-cleanup.h"
+
#define LCMS_CURVE_PLUGIN_TYPE_REC709 1024
typedef struct {
@@ -85,12 +87,6 @@ cd_util_create_colprof (CdUtilPrivate *priv,
const GNode *node_stpo;
const GNode *tmp;
gboolean ret = FALSE;
- gchar *cmdline = NULL;
- gchar *debug_stdout = NULL;
- gchar *debug_stderr = NULL;
- gchar *data = NULL;
- gchar *output_fn = NULL;
- gchar *ti3_fn = NULL;
gdouble enle;
gdouble enpo;
gdouble klimit;
@@ -98,17 +94,23 @@ cd_util_create_colprof (CdUtilPrivate *priv,
gdouble stle;
gdouble stpo;
gdouble tlimit;
- GFile *output_file = NULL;
- GFile *ti3_file = NULL;
gint exit_status = 0;
- GPtrArray *argv = NULL;
gsize len = 0;
+ _cleanup_free_ gchar *cmdline = NULL;
+ _cleanup_free_ gchar *data = NULL;
+ _cleanup_free_ gchar *debug_stderr = NULL;
+ _cleanup_free_ gchar *debug_stdout = NULL;
+ _cleanup_free_ gchar *output_fn = NULL;
+ _cleanup_free_ gchar *ti3_fn = NULL;
+ _cleanup_object_unref_ GFile *output_file = NULL;
+ _cleanup_object_unref_ GFile *ti3_file = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *argv = NULL;
#ifndef TOOL_COLPROF
/* no support */
g_set_error_literal (error, 1, 0,
"not compiled with --enable-print-profiles");
- goto out;
+ return FALSE;
#endif
/* create common options */
@@ -135,10 +137,9 @@ cd_util_create_colprof (CdUtilPrivate *priv,
shape = cd_dom_get_node_data_as_double (node_shape);
if (stle == G_MAXDOUBLE || stpo == G_MAXDOUBLE || enpo == G_MAXDOUBLE ||
enle == G_MAXDOUBLE || shape == G_MAXDOUBLE) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"XML error: invalid stle, stpo, enpo, enle, shape");
- goto out;
+ return FALSE;
}
g_ptr_array_add (argv, g_strdup ("-kp"));
g_ptr_array_add (argv, g_strdup_printf ("%f", stle));
@@ -153,10 +154,9 @@ cd_util_create_colprof (CdUtilPrivate *priv,
if (tmp != NULL) {
tlimit = cd_dom_get_node_data_as_double (tmp);
if (tlimit == G_MAXDOUBLE) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"XML error: invalid tlimit");
- goto out;
+ return FALSE;
}
g_ptr_array_add (argv, g_strdup_printf ("-l%.0f", tlimit));
}
@@ -166,10 +166,9 @@ cd_util_create_colprof (CdUtilPrivate *priv,
if (tmp != NULL) {
klimit = cd_dom_get_node_data_as_double (tmp);
if (klimit == G_MAXDOUBLE) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"XML error: invalid klimit");
- goto out;
+ return FALSE;
}
g_ptr_array_add (argv, g_strdup_printf ("-L%.0f", klimit));
}
@@ -191,10 +190,9 @@ cd_util_create_colprof (CdUtilPrivate *priv,
/* get source filename and copy into working directory */
tmp = cd_dom_get_node (dom, root, "data_ti3");
if (tmp == NULL) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"XML error: no data_ti3");
- goto out;
+ return FALSE;
}
data_ti3 = cd_dom_get_node_data (tmp);
ti3_fn = g_strdup_printf ("/tmp/%s.ti3", basename);
@@ -209,15 +207,14 @@ cd_util_create_colprof (CdUtilPrivate *priv,
NULL,
error);
if (!ret)
- goto out;
+ return FALSE;
/* ensure temporary icc profile does not already exist */
output_fn = g_strdup_printf ("/tmp/%s.icc", basename);
output_file = g_file_new_for_path (output_fn);
if (g_file_query_exists (output_file, NULL)) {
- ret = g_file_delete (output_file, NULL, error);
- if (!ret)
- goto out;
+ if (!g_file_delete (output_file, NULL, error))
+ return FALSE;
}
/* run colprof in working directory */
@@ -234,54 +231,37 @@ cd_util_create_colprof (CdUtilPrivate *priv,
&exit_status,
error);
if (!ret)
- goto out;
+ return FALSE;
/* failed */
if (exit_status != 0) {
- ret = FALSE;
cmdline = g_strjoinv (" ", (gchar **) argv->pdata);
g_set_error (error, 1, 0,
"Failed to generate %s using '%s'\nOutput: %s\nError:\t%s",
output_fn, cmdline, debug_stdout, debug_stderr);
- goto out;
+ return FALSE;
}
/* load resulting .icc file */
- ret = g_file_load_contents (output_file, NULL, &data, &len, NULL, error);
- if (!ret)
- goto out;
+ if (!g_file_load_contents (output_file, NULL, &data, &len, NULL, error))
+ return FALSE;
/* open /tmp/$basename.icc as hProfile */
priv->lcms_profile = cmsOpenProfileFromMemTHR (cd_icc_get_context (priv->icc),
data, len);
if (priv->lcms_profile == NULL) {
- ret = FALSE;
g_set_error (error, 1, 0,
"Failed to open generated %s",
output_fn);
- goto out;
+ return FALSE;
}
/* delete temp files */
- ret = g_file_delete (output_file, NULL, error);
- if (!ret)
- goto out;
- ret = g_file_delete (ti3_file, NULL, error);
- if (!ret)
- goto out;
-out:
- if (ti3_file != NULL)
- g_object_unref (ti3_file);
- if (output_file != NULL)
- g_object_unref (output_file);
- g_free (debug_stdout);
- g_free (debug_stderr);
- g_free (data);
- g_free (cmdline);
- g_free (output_fn);
- if (argv != NULL)
- g_ptr_array_unref (argv);
- return ret;
+ if (!g_file_delete (output_file, NULL, error))
+ return FALSE;
+ if (!g_file_delete (ti3_file, NULL, error))
+ return FALSE;
+ return TRUE;
}
/**
@@ -380,14 +360,12 @@ cd_util_create_x11_gamma (CdUtilPrivate *priv,
/* parse gamma values */
tmp = cd_dom_get_node (dom, root, "x11_gamma");
if (tmp == NULL) {
- ret = FALSE;
g_set_error_literal (error, 1, 0, "XML error, expected x11_gamma");
- goto out;
+ return FALSE;
}
- ret = cd_dom_get_node_rgb (tmp, &rgb);
- if (!ret) {
+ if (!cd_dom_get_node_rgb (tmp, &rgb)) {
g_set_error_literal (error, 1, 0, "XML error, invalid x11_gamma");
- goto out;
+ return FALSE;
}
points[0] = rgb.R;
points[1] = rgb.G;
@@ -396,10 +374,8 @@ cd_util_create_x11_gamma (CdUtilPrivate *priv,
/* create a bog-standard sRGB profile */
priv->lcms_profile = cmsCreate_sRGBProfileTHR (cd_icc_get_context (priv->icc));
if (priv->lcms_profile == NULL) {
- ret = FALSE;
- g_set_error_literal (error, 1, 0,
- "failed to create profile");
- goto out;
+ g_set_error_literal (error, 1, 0, "failed to create profile");
+ return FALSE;
}
/* scale all the values by the floating point values */
@@ -418,10 +394,9 @@ cd_util_create_x11_gamma (CdUtilPrivate *priv,
if (!ret) {
g_set_error_literal (error, 1, 0,
"failed to write VCGT");
- goto out;
+ return FALSE;
}
-out:
- return ret;
+ return TRUE;
}
/**
@@ -630,35 +605,31 @@ cd_util_create_temperature (CdUtilPrivate *priv,
/* create a bog-standard sRGB profile */
priv->lcms_profile = cmsCreate_sRGBProfileTHR (cd_icc_get_context (priv->icc));
if (priv->lcms_profile == NULL) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"failed to create profile");
- goto out;
+ return FALSE;
}
/* parse temperature value */
tmp = cd_dom_get_node (dom, root, "temperature");
if (tmp == NULL) {
- ret = FALSE;
g_set_error_literal (error, 1, 0, "XML error, expected temperature");
- goto out;
+ return FALSE;
}
temp = atoi (cd_dom_get_node_data (tmp));
/* parse gamma value */
tmp = cd_dom_get_node (dom, root, "gamma");
if (tmp == NULL) {
- ret = FALSE;
g_set_error_literal (error, 1, 0, "XML error, expected gamma");
- goto out;
+ return FALSE;
}
curve_gamma = cd_dom_get_node_data_as_double (tmp);
if (curve_gamma == G_MAXDOUBLE) {
- ret = FALSE;
g_set_error (error, 1, 0,
"failed to parse gamma: '%s'",
cd_dom_get_node_data (tmp));
- goto out;
+ return FALSE;
}
/* generate the VCGT table */
@@ -679,12 +650,10 @@ cd_util_create_temperature (CdUtilPrivate *priv,
data[2],
256);
if (!ret) {
- g_set_error_literal (error, 1, 0,
- "failed to write VCGT");
- goto out;
+ g_set_error_literal (error, 1, 0, "failed to write VCGT");
+ return FALSE;
}
-out:
- return ret;
+ return TRUE;
}
/**
@@ -693,36 +662,29 @@ out:
static gboolean
cd_util_icc_set_metadata_coverage (CdIcc *icc, GError **error)
{
- CdIcc *icc_srgb = NULL;
const gchar *tmp;
- gboolean ret = TRUE;
- gchar *coverage_tmp = NULL;
gdouble coverage = 0.0f;
+ _cleanup_free_ gchar *coverage_tmp = NULL;
+ _cleanup_object_unref_ CdIcc *icc_srgb = NULL;
/* is sRGB? */
tmp = cd_icc_get_metadata_item (icc, CD_PROFILE_METADATA_STANDARD_SPACE);
if (g_strcmp0 (tmp, "srgb") == 0)
- goto out;
+ return TRUE;
/* calculate coverage (quite expensive to calculate, hence metadata) */
icc_srgb = cd_icc_new ();
- ret = cd_icc_create_default (icc_srgb, error);
- if (!ret)
- goto out;
- ret = cd_icc_utils_get_coverage (icc_srgb, icc, &coverage, error);
- if (!ret)
- goto out;
+ if (!cd_icc_create_default (icc_srgb, error))
+ return FALSE;
+ if (!cd_icc_utils_get_coverage (icc_srgb, icc, &coverage, error))
+ return FALSE;
if (coverage > 0.0) {
coverage_tmp = g_strdup_printf ("%.2f", coverage);
cd_icc_add_metadata (icc,
"GAMUT_coverage(srgb)",
coverage_tmp);
}
-out:
- g_free (coverage_tmp);
- if (icc_srgb != NULL)
- g_object_unref (icc_srgb);
- return ret;
+ return TRUE;
}
/**
@@ -733,67 +695,54 @@ cd_util_create_from_xml (CdUtilPrivate *priv,
const gchar *filename,
GError **error)
{
- CdDom *dom = NULL;
const GNode *profile;
const GNode *tmp;
gboolean ret = TRUE;
- gchar *data = NULL;
GHashTable *hash;
gssize data_len = -1;
+ _cleanup_free_ gchar *data = NULL;
+ _cleanup_object_unref_ CdDom *dom = NULL;
/* parse the XML into DOM */
- ret = g_file_get_contents (filename, &data, (gsize *) &data_len, error);
- if (!ret)
- goto out;
+ if (!g_file_get_contents (filename, &data, (gsize *) &data_len, error))
+ return FALSE;
dom = cd_dom_new ();
- ret = cd_dom_parse_xml_data (dom, data, data_len, error);
- if (!ret)
- goto out;
+ if (!cd_dom_parse_xml_data (dom, data, data_len, error))
+ return FALSE;
/* get root */
profile = cd_dom_get_node (dom, NULL, "profile");
if (profile == NULL) {
- ret = FALSE;
- g_set_error_literal (error, 1, 0,
- "invalid XML, expected profile");
- goto out;
+ g_set_error_literal (error, 1, 0, "invalid XML, expected profile");
+ return FALSE;
}
/* get type */
if (cd_dom_get_node (dom, profile, "primaries") != NULL) {
- ret = cd_util_create_standard_space (priv, dom, profile, error);
- if (!ret)
- goto out;
+ if (!cd_util_create_standard_space (priv, dom, profile, error))
+ return FALSE;
} else if (cd_dom_get_node (dom, profile, "temperature") != NULL) {
- ret = cd_util_create_temperature (priv, dom, profile, error);
- if (!ret)
- goto out;
+ if (!cd_util_create_temperature (priv, dom, profile, error))
+ return FALSE;
} else if (cd_dom_get_node (dom, profile, "x11_gamma") != NULL) {
- ret = cd_util_create_x11_gamma (priv, dom, profile, error);
- if (!ret)
- goto out;
+ if (!cd_util_create_x11_gamma (priv, dom, profile, error))
+ return FALSE;
} else if (cd_dom_get_node (dom, profile, "named") != NULL) {
- ret = cd_util_create_named_color (priv, dom, profile, error);
- if (!ret)
- goto out;
+ if (!cd_util_create_named_color (priv, dom, profile, error))
+ return FALSE;
} else if (cd_dom_get_node (dom, profile, "data_ti3") != NULL) {
- ret = cd_util_create_colprof (priv, dom, profile, error);
- if (!ret)
- goto out;
+ if (!cd_util_create_colprof (priv, dom, profile, error))
+ return FALSE;
} else {
- ret = FALSE;
- g_set_error_literal (error, 1, 0,
- "invalid XML, unknown type");
- goto out;
+ g_set_error_literal (error, 1, 0, "invalid XML, unknown type");
+ return FALSE;
}
/* convert into a CdIcc object */
- ret = cd_icc_load_handle (priv->icc,
- priv->lcms_profile,
- CD_ICC_LOAD_FLAGS_NONE,
- error);
+ ret = cd_icc_load_handle (priv->icc, priv->lcms_profile,
+ CD_ICC_LOAD_FLAGS_NONE, error);
if (!ret)
- goto out;
+ return FALSE;
/* also write metadata */
tmp = cd_dom_get_node (dom, profile, "license");
@@ -807,9 +756,8 @@ cd_util_create_from_xml (CdUtilPrivate *priv,
cd_icc_add_metadata (priv->icc,
CD_PROFILE_METADATA_STANDARD_SPACE,
cd_dom_get_node_data (tmp));
- ret = cd_util_icc_set_metadata_coverage (priv->icc, error);
- if (!ret)
- goto out;
+ if (!cd_util_icc_set_metadata_coverage (priv->icc, error))
+ return FALSE;
}
tmp = cd_dom_get_node (dom, profile, "data_source");
if (tmp != NULL) {
@@ -842,11 +790,7 @@ cd_util_create_from_xml (CdUtilPrivate *priv,
hash = cd_dom_get_node_localized (profile, "manufacturer");
if (hash != NULL)
cd_icc_set_manufacturer_items (priv->icc, hash);
-out:
- g_free (data);
- if (dom != NULL)
- g_object_unref (dom);
- return ret;
+ return TRUE;
}
/**
@@ -857,12 +801,11 @@ main (int argc, char **argv)
{
CdUtilPrivate *priv;
gboolean ret;
- gchar *cmd_descriptions = NULL;
- gchar *filename = NULL;
- GError *error = NULL;
- GFile *file = NULL;
guint retval = EXIT_FAILURE;
-
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *cmd_descriptions = NULL;
+ _cleanup_free_ gchar *filename = NULL;
+ _cleanup_object_unref_ GFile *file = NULL;
const GOptionEntry options[] = {
{ "output", 'o', 0, G_OPTION_ARG_STRING, &filename,
/* TRANSLATORS: command line option */
@@ -886,10 +829,8 @@ main (int argc, char **argv)
ret = g_option_context_parse (priv->context, &argc, &argv, &error);
if (!ret) {
/* TRANSLATORS: the user didn't read the man page */
- g_print ("%s: %s\n",
- _("Failed to parse arguments"),
+ g_print ("%s: %s\n", _("Failed to parse arguments"),
error->message);
- g_error_free (error);
goto out;
}
@@ -904,7 +845,6 @@ main (int argc, char **argv)
ret = cd_util_create_from_xml (priv, argv[1], &error);
if (!ret) {
g_print ("%s\n", error->message);
- g_error_free (error);
goto out;
}
@@ -917,7 +857,6 @@ main (int argc, char **argv)
&error);
if (!ret) {
g_print ("%s\n", error->message);
- g_error_free (error);
goto out;
}
@@ -929,10 +868,6 @@ out:
g_object_unref (priv->icc);
g_free (priv);
}
- if (file != NULL)
- g_object_unref (file);
- g_free (cmd_descriptions);
- g_free (filename);
return retval;
}
diff --git a/client/cd-find-broken.c b/client/cd-find-broken.c
index 7023ea6..990fa43 100644
--- a/client/cd-find-broken.c
+++ b/client/cd-find-broken.c
@@ -25,6 +25,8 @@
#include <colord.h>
#include <locale.h>
+#include "cd-cleanup.h"
+
typedef struct {
GHashTable *cmfbinary;
GHashTable *vendors;
@@ -43,26 +45,24 @@ cd_find_broken_parse_filename (CdFindBrokenPriv *priv,
const gchar *filename,
GError **error)
{
- CdIcc *icc = NULL;
CdProfileWarning warning;
const gchar *tmp;
- GArray *warnings = NULL;
gboolean ret;
- gchar *vendor = NULL;
- GFile *file = NULL;
guint i;
guint *val;
+ _cleanup_array_unref_ GArray *warnings = NULL;
+ _cleanup_free_ gchar *vendor = NULL;
+ _cleanup_object_unref_ CdIcc *icc = NULL;
+ _cleanup_object_unref_ GFile *file = NULL;
/* load file */
icc = cd_icc_new ();
file = g_file_new_for_path (filename);
- ret = cd_icc_load_file (icc,
- file,
+ ret = cd_icc_load_file (icc, file,
CD_ICC_LOAD_FLAGS_METADATA | CD_ICC_LOAD_FLAGS_PRIMARIES,
- NULL,
- error);
+ NULL, error);
if (!ret)
- goto out;
+ return FALSE;
/* append to CSV file */
g_string_append_printf (priv->csv_all, "%s,\"%s\",\"%s\",%s,%s,%.1f,%s,%s\n",
@@ -115,7 +115,7 @@ cd_find_broken_parse_filename (CdFindBrokenPriv *priv,
/* any problems */
warnings = cd_icc_get_warnings (icc);
if (warnings->len == 0)
- goto out;
+ return FALSE;
/* count those with problems */
val = g_hash_table_lookup (priv->vendors_broken, vendor);
@@ -136,13 +136,7 @@ cd_find_broken_parse_filename (CdFindBrokenPriv *priv,
cd_profile_warning_to_string (warning));
}
priv->csv_fail->str[priv->csv_fail->len - 1] = '\n';
-out:
- if (warnings != NULL)
- g_array_unref (warnings);
- g_object_unref (file);
- g_object_unref (icc);
- g_free (vendor);
- return ret;
+ return TRUE;
}
/**
@@ -164,7 +158,6 @@ main (int argc, char *argv[])
const gchar *fn_all = "./all.csv";
const gchar *fn_failures = "./results.csv";
gboolean ret;
- GError *error = NULL;
gint retval = EXIT_FAILURE;
GList *l;
GList *list;
@@ -172,6 +165,7 @@ main (int argc, char *argv[])
guint total = 0;
guint total_with_warnings = 0;
guint *val;
+ _cleanup_error_free_ GError *error = NULL;
if (argc < 2) {
g_warning ("usage: cd-find-broken.c filename, e.g. 'uploads/*'");
@@ -266,13 +260,11 @@ main (int argc, char *argv[])
ret = g_file_set_contents (fn_all, priv->csv_all->str, -1, &error);
if (!ret) {
g_warning ("%s", error->message);
- g_error_free (error);
goto out;
}
ret = g_file_set_contents (fn_failures, priv->csv_fail->str, -1, &error);
if (!ret) {
g_warning ("%s", error->message);
- g_error_free (error);
goto out;
}
diff --git a/client/cd-fix-profile.c b/client/cd-fix-profile.c
index d919b0d..136d8c7 100644
--- a/client/cd-fix-profile.c
+++ b/client/cd-fix-profile.c
@@ -28,6 +28,8 @@
#include <stdlib.h>
#include <colord/colord.h>
+#include "cd-cleanup.h"
+
#define CD_PROFILE_DEFAULT_COPYRIGHT_STRING "This profile is free of known copyright restrictions."
typedef struct {
@@ -76,8 +78,8 @@ static void
cd_util_add (GPtrArray *array, const gchar *name, const gchar *description, CdUtilPrivateCb callback)
{
CdUtilItem *item;
- gchar **names;
guint i;
+ _cleanup_strv_free_ gchar **names = NULL;
/* add each one */
names = g_strsplit (name, ",", -1);
@@ -94,7 +96,6 @@ cd_util_add (GPtrArray *array, const gchar *name, const gchar *description, CdUt
item->callback = callback;
g_ptr_array_add (array, item);
}
- g_strfreev (names);
}
/**
@@ -149,17 +150,14 @@ static gboolean
cd_util_run (CdUtilPrivate *priv, const gchar *command, gchar **values, GError **error)
{
CdUtilItem *item;
- gboolean ret = FALSE;
- GString *string;
guint i;
+ _cleanup_string_free_ GString *string = NULL;
/* find command */
for (i = 0; i < priv->cmd_array->len; i++) {
item = g_ptr_array_index (priv->cmd_array, i);
- if (g_strcmp0 (item->name, command) == 0) {
- ret = item->callback (priv, values, error);
- goto out;
- }
+ if (g_strcmp0 (item->name, command) == 0)
+ return item->callback (priv, values, error);
}
/* not found */
@@ -172,9 +170,7 @@ cd_util_run (CdUtilPrivate *priv, const gchar *command, gchar **values, GError *
g_string_append_printf (string, " * %s\n", item->name);
}
g_set_error_literal (error, 1, 0, string->str);
- g_string_free (string, TRUE);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -183,14 +179,10 @@ out:
static gboolean
cd_util_set_copyright (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
-
- /* check arguments */
if (g_strv_length (values) != 2) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename' 'value'");
- goto out;
+ return FALSE;
}
/* set new value */
@@ -203,8 +195,7 @@ cd_util_set_copyright (CdUtilPrivate *priv, gchar **values, GError **error)
priv->locale,
values[1]);
}
-out:
- return ret;
+ return TRUE;
}
/**
@@ -213,20 +204,16 @@ out:
static gboolean
cd_util_set_description (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
-
/* check arguments */
if (g_strv_length (values) != 2) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename' 'value'");
- goto out;
+ return FALSE;
}
/* set new value */
cd_icc_set_description (priv->icc, priv->locale, values[1]);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -235,20 +222,16 @@ out:
static gboolean
cd_util_set_manufacturer (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
-
/* check arguments */
if (g_strv_length (values) != 2) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename' 'value'");
- goto out;
+ return FALSE;
}
/* set new value */
cd_icc_set_manufacturer (priv->icc, priv->locale, values[1]);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -257,20 +240,16 @@ out:
static gboolean
cd_util_set_model (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
-
/* check arguments */
if (g_strv_length (values) != 2) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename' 'value'");
- goto out;
+ return FALSE;
}
/* set new value */
cd_icc_set_model (priv->icc, priv->locale, values[1]);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -279,13 +258,11 @@ out:
static gboolean
cd_util_clear_metadata (CdUtilPrivate *priv, gchar **values, GError **error)
{
- GHashTable *md;
+ _cleanup_hashtable_unref_ GHashTable *md = NULL;
md = cd_icc_get_metadata (priv->icc);
if (md == NULL)
- goto out;
+ return TRUE;
g_hash_table_remove_all (md);
- g_hash_table_unref (md);
-out:
return TRUE;
}
@@ -297,29 +274,23 @@ cd_util_get_standard_space_filename (CdUtilPrivate *priv,
CdStandardSpace standard_space,
GError **error)
{
- CdProfile *profile_tmp = NULL;
- gboolean ret;
gchar *filename = NULL;
+ _cleanup_object_unref_ CdProfile *profile_tmp = NULL;
/* try to find */
- ret = cd_client_connect_sync (priv->client, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_client_connect_sync (priv->client, NULL, error))
+ return NULL;
profile_tmp = cd_client_get_standard_space_sync (priv->client,
standard_space,
NULL,
error);
if (profile_tmp == NULL)
- goto out;
+ return NULL;
/* get filename */
- ret = cd_profile_connect_sync (profile_tmp, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_profile_connect_sync (profile_tmp, NULL, error))
+ return NULL;
filename = g_strdup (cd_profile_get_filename (profile_tmp));
-out:
- if (profile_tmp != NULL)
- g_object_unref (profile_tmp);
return filename;
}
@@ -361,7 +332,7 @@ cd_util_get_coverage (cmsHPROFILE profile_proof,
/* get coverage */
ret = cd_icc_utils_get_coverage (icc, icc_ref, &coverage, error);
if (!ret)
- goto out;
+ return FALSE;
out:
if (file != NULL)
g_object_unref (file);
@@ -406,38 +377,33 @@ out:
static gboolean
cd_util_set_version (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
gchar *endptr = NULL;
gdouble version;
/* check arguments */
if (g_strv_length (values) != 2) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename' 'version'");
- goto out;
+ return FALSE;
}
/* get version */
version = g_ascii_strtod (values[1], &endptr);
if (endptr != NULL && endptr[0] != '\0') {
- ret = FALSE;
g_set_error (error, 1, 0,
"failed to parse version: '%s'",
values[1]);
- goto out;
+ return FALSE;
}
if (version < 1.0 || version > 6.0) {
- ret = FALSE;
g_set_error (error, 1, 0,
"invalid version %f", version);
- goto out;
+ return FALSE;
}
/* set version */
cd_icc_set_version (priv->icc, version);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -446,24 +412,21 @@ out:
static gboolean
cd_util_export_tag_data (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
- GBytes *data = NULL;
- gchar *out_fn = NULL;
+ gboolean ret;
+ _cleanup_bytes_unref_ GBytes *data = NULL;
+ _cleanup_free_ gchar *out_fn = NULL;
/* check arguments */
if (g_strv_length (values) != 2) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename' 'tag'");
- goto out;
+ return FALSE;
}
/* get data */
data = cd_icc_get_tag_data (priv->icc, values[1], error);
- if (data == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (data == NULL)
+ return FALSE;
/* save to file */
out_fn = g_strdup_printf ("./%s.bin", values[1]);
@@ -472,14 +435,10 @@ cd_util_export_tag_data (CdUtilPrivate *priv, gchar **values, GError **error)
g_bytes_get_size (data),
error);
if (!ret)
- goto out;
+ return FALSE;
g_print ("Wrote %s\n", out_fn);
priv->rewrite_file = FALSE;
-out:
- if (data != NULL)
- g_bytes_unref (data);
- g_free (out_fn);
- return ret;
+ return TRUE;
}
/**
@@ -488,16 +447,14 @@ out:
static gboolean
cd_util_set_fix_metadata (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
gchar *coverage_tmp;
gdouble coverage;
/* check arguments */
if (g_strv_length (values) != 1) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename'");
- goto out;
+ return FALSE;
}
/* get coverages of common spaces */
@@ -507,10 +464,8 @@ cd_util_set_fix_metadata (CdUtilPrivate *priv, gchar **values, GError **error)
coverage = cd_util_get_profile_coverage (priv,
CD_STANDARD_SPACE_ADOBE_RGB,
error);
- if (coverage < 0.0) {
- ret = FALSE;
- goto out;
- }
+ if (coverage < 0.0)
+ return FALSE;
coverage_tmp = g_strdup_printf ("%f", coverage);
cd_icc_add_metadata (priv->icc,
"GAMUT_coverage(adobe-rgb)",
@@ -522,10 +477,8 @@ cd_util_set_fix_metadata (CdUtilPrivate *priv, gchar **values, GError **error)
coverage = cd_util_get_profile_coverage (priv,
CD_STANDARD_SPACE_SRGB,
error);
- if (coverage < 0.0) {
- ret = FALSE;
- goto out;
- }
+ if (coverage < 0.0)
+ return FALSE;
coverage_tmp = g_strdup_printf ("%.2f", coverage);
cd_icc_add_metadata (priv->icc,
"GAMUT_coverage(srgb)",
@@ -538,8 +491,7 @@ cd_util_set_fix_metadata (CdUtilPrivate *priv, gchar **values, GError **error)
cd_icc_add_metadata (priv->icc,
CD_PROFILE_METADATA_CMF_VERSION,
PACKAGE_VERSION);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -548,14 +500,11 @@ out:
static gboolean
cd_util_init_metadata (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
-
/* check arguments */
if (g_strv_length (values) != 1) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename'");
- goto out;
+ return FALSE;
}
/* add CMS defines */
@@ -568,8 +517,7 @@ cd_util_init_metadata (CdUtilPrivate *priv, gchar **values, GError **error)
cd_icc_add_metadata (priv->icc,
CD_PROFILE_METADATA_CMF_VERSION,
PACKAGE_VERSION);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -578,20 +526,16 @@ out:
static gboolean
cd_util_remove_metadata (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
-
/* check arguments */
if (g_strv_length (values) != 2) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename' 'key'");
- goto out;
+ return FALSE;
}
/* remove entry */
cd_icc_remove_metadata (priv->icc, values[1]);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -600,20 +544,16 @@ out:
static gboolean
cd_util_add_metadata (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
-
/* check arguments */
if (g_strv_length (values) != 3) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename' 'key' 'value'");
- goto out;
+ return FALSE;
}
/* add new entry */
cd_icc_add_metadata (priv->icc, values[1], values[2]);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -625,35 +565,31 @@ cd_util_extract_vcgt (CdUtilPrivate *priv, gchar **values, GError **error)
cmsFloat32Number in;
cmsHPROFILE lcms_profile;
const cmsToneCurve **vcgt;
- gboolean ret = TRUE;
guint i;
guint size;
/* check arguments */
if (g_strv_length (values) != 2) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid input, expect 'filename' size'");
- goto out;
+ return FALSE;
}
/* invalid size */
size = atoi (values[1]);
if (size <= 1 || size > 1024) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"invalid size,expected 2-1024");
- goto out;
+ return FALSE;
}
/* does profile have VCGT */
lcms_profile = cd_icc_get_handle (priv->icc);
vcgt = cmsReadTag (lcms_profile, cmsSigVcgtTag);
if (vcgt == NULL || vcgt[0] == NULL) {
- ret = FALSE;
g_set_error_literal (error, 1, 0,
"profile does not have any VCGT data");
- goto out;
+ return FALSE;
}
/* output data */
@@ -668,9 +604,7 @@ cd_util_extract_vcgt (CdUtilPrivate *priv, gchar **values, GError **error)
/* success */
priv->rewrite_file = FALSE;
- ret = TRUE;
-out:
- return ret;
+ return TRUE;
}
/**
@@ -702,11 +636,11 @@ main (int argc, char *argv[])
CdUtilPrivate *priv;
gboolean ret = TRUE;
gboolean verbose = FALSE;
- gchar *cmd_descriptions = NULL;
- gchar *locale = NULL;
- GError *error = NULL;
- GFile *file = NULL;
guint retval = 1;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *cmd_descriptions = NULL;
+ _cleanup_free_ gchar *locale = NULL;
+ _cleanup_object_unref_ GFile *file = NULL;
const GOptionEntry options[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
/* TRANSLATORS: command line option */
@@ -807,10 +741,8 @@ main (int argc, char *argv[])
ret = g_option_context_parse (priv->context, &argc, &argv, &error);
if (!ret) {
/* TRANSLATORS: the user didn't read the man page */
- g_print ("%s: %s\n",
- _("Failed to parse arguments"),
+ g_print ("%s: %s\n", _("Failed to parse arguments"),
error->message);
- g_error_free (error);
goto out;
}
@@ -841,7 +773,6 @@ main (int argc, char *argv[])
&error);
if (!ret) {
g_print ("%s\n", error->message);
- g_error_free (error);
goto out;
}
@@ -849,7 +780,6 @@ main (int argc, char *argv[])
ret = cd_util_run (priv, argv[2], (gchar**) &argv[2], &error);
if (!ret) {
g_print ("%s\n", error->message);
- g_error_free (error);
goto out;
}
@@ -862,7 +792,6 @@ main (int argc, char *argv[])
&error);
if (!ret) {
g_print ("%s\n", error->message);
- g_error_free (error);
goto out;
}
}
@@ -880,10 +809,6 @@ out:
g_free (priv->locale);
g_free (priv);
}
- if (file != NULL)
- g_object_unref (file);
- g_free (locale);
- g_free (cmd_descriptions);
return retval;
}
diff --git a/client/cd-iccdump.c b/client/cd-iccdump.c
index fcf1a9e..43e411d 100644
--- a/client/cd-iccdump.c
+++ b/client/cd-iccdump.c
@@ -29,6 +29,8 @@
#include <math.h>
#include <colord-private.h>
+#include "cd-cleanup.h"
+
static gint lcms_error_code = 0;
/**
@@ -51,30 +53,20 @@ cd_fix_profile_error_cb (cmsContext ContextID,
static gboolean
cd_iccdump_print_file (const gchar *filename, GError **error)
{
- CdIcc *icc;
- gboolean ret;
- gchar *str = NULL;
- GFile *file;
+ _cleanup_free_ gchar *str = NULL;
+ _cleanup_object_unref_ CdIcc *icc = NULL;
+ _cleanup_object_unref_ GFile *file = NULL;
/* load the profile */
icc = cd_icc_new ();
file = g_file_new_for_path (filename);
- ret = cd_icc_load_file (icc,
- file,
- CD_ICC_LOAD_FLAGS_NONE,
- NULL,
- error);
- if (!ret)
- goto out;
+ if (!cd_icc_load_file (icc, file, CD_ICC_LOAD_FLAGS_NONE, NULL, error))
+ return FALSE;
/* dump it to text on the console */
str = cd_icc_to_string (icc);
g_print ("%s\n", str);
-out:
- g_free (str);
- g_object_unref (file);
- g_object_unref (icc);
- return ret;
+ return TRUE;
}
/**
@@ -84,10 +76,10 @@ int
main (int argc, char **argv)
{
gboolean ret;
- GError *error = NULL;
GOptionContext *context;
gint i;
guint retval = EXIT_FAILURE;
+ _cleanup_error_free_ GError *error = NULL;
setlocale (LC_ALL, "");
@@ -104,10 +96,8 @@ main (int argc, char **argv)
ret = g_option_context_parse (context, &argc, &argv, &error);
if (!ret) {
/* TRANSLATORS: the user didn't read the man page */
- g_print ("%s: %s\n",
- _("Failed to parse arguments"),
+ g_print ("%s: %s\n", _("Failed to parse arguments"),
error->message);
- g_error_free (error);
goto out;
}
@@ -117,7 +107,6 @@ main (int argc, char **argv)
if (!ret) {
g_warning ("Failed to dump %s: %s",
argv[i], error->message);
- g_error_free (error);
goto out;
}
}
@@ -128,4 +117,3 @@ out:
g_option_context_free (context);
return retval;
}
-
diff --git a/client/cd-it8.c b/client/cd-it8.c
index 4a891d3..162268d 100644
--- a/client/cd-it8.c
+++ b/client/cd-it8.c
@@ -82,9 +82,9 @@ cd_util_add (GPtrArray *array,
const gchar *description,
CdUtilPrivateCb callback)
{
- gchar **names;
guint i;
CdUtilItem *item;
+ _cleanup_strv_free_ gchar **names = NULL;
g_return_if_fail (name != NULL);
g_return_if_fail (description != NULL);
@@ -106,7 +106,6 @@ cd_util_add (GPtrArray *array,
item->callback = callback;
g_ptr_array_add (array, item);
}
- g_strfreev (names);
}
/**
@@ -161,18 +160,15 @@ cd_util_get_descriptions (GPtrArray *array)
static gboolean
cd_util_run (CdUtilPrivate *priv, const gchar *command, gchar **values, GError **error)
{
- gboolean ret = FALSE;
guint i;
CdUtilItem *item;
- GString *string;
+ _cleanup_string_free_ GString *string = NULL;
/* find command */
for (i = 0; i < priv->cmd_array->len; i++) {
item = g_ptr_array_index (priv->cmd_array, i);
- if (g_strcmp0 (item->name, command) == 0) {
- ret = item->callback (priv, values, error);
- goto out;
- }
+ if (g_strcmp0 (item->name, command) == 0)
+ return item->callback (priv, values, error);
}
/* not found */
@@ -187,9 +183,7 @@ cd_util_run (CdUtilPrivate *priv, const gchar *command, gchar **values, GError *
item->arguments ? item->arguments : "");
}
g_set_error_literal (error, CD_ERROR, CD_ERROR_NO_SUCH_CMD, string->str);
- g_string_free (string, TRUE);
-out:
- return ret;
+ return FALSE;
}
typedef struct {
@@ -215,39 +209,37 @@ cd_util_create_cmf (CdUtilPrivate *priv,
GError **error)
{
gboolean ret = TRUE;
- CdIt8 *cmf = NULL;
CdSpectrum *spectrum[3] = { NULL, NULL, NULL };
CdSpectrumData *tmp;
- GFile *file = NULL;
- GPtrArray *array = NULL;
- gchar **lines = NULL;
- gchar **split;
- gchar *data = NULL;
gchar *dot;
- gchar *title = NULL;
guint i;
gdouble norm;
+ _cleanup_free_ gchar *data = NULL;
+ _cleanup_free_ gchar *title = NULL;
+ _cleanup_object_unref_ CdIt8 *cmf = NULL;
+ _cleanup_object_unref_ GFile *file = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
+ _cleanup_strv_free_ gchar **lines = NULL;
if (g_strv_length (values) != 3) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, expected: "
"file.cmf file.csv norm");
- goto out;
+ return FALSE;
}
/* get data */
- ret = g_file_get_contents (values[1], &data, NULL, error);
- if (!ret)
- goto out;
+ if (!g_file_get_contents (values[1], &data, NULL, error))
+ return FALSE;
/* parse lines */
norm = g_strtod (values[2], NULL);
array = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_csv2cmf_data_free);
lines = g_strsplit (data, "\n", -1);
for (i = 0; lines[i] != NULL; i++) {
+ _cleanup_strv_free_ gchar **split = NULL;
if (lines[i][0] == '\0')
continue;
if (lines[i][0] == '#')
@@ -264,17 +256,15 @@ cd_util_create_cmf (CdUtilPrivate *priv,
} else {
g_printerr ("Ignoring data line: %s", lines[i]);
}
- g_strfreev (split);
}
/* did we get enough data */
if (array->len < 3) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough data in the CSV file");
- goto out;
+ return FALSE;
}
for (i = 0; i < 3; i++) {
@@ -327,15 +317,6 @@ out:
if (spectrum[i] != NULL)
cd_spectrum_free (spectrum[i]);
}
- if (array != NULL)
- g_ptr_array_unref (array);
- if (cmf != NULL)
- g_object_unref (cmf);
- if (file != NULL)
- g_object_unref (file);
- g_free (data);
- g_free (title);
- g_strfreev (lines);
return ret;
}
@@ -403,39 +384,37 @@ cd_util_create_sp (CdUtilPrivate *priv,
gchar **values,
GError **error)
{
- CdIt8 *cmf = NULL;
CdSpectrum *spectrum = NULL;
CdSpectrumData *tmp;
- GFile *file = NULL;
- GPtrArray *array = NULL;
gboolean ret = TRUE;
- gchar **lines = NULL;
- gchar **split;
- gchar *data = NULL;
gchar *dot;
- gchar *title = NULL;
gdouble norm;
guint i;
+ _cleanup_free_ gchar *data = NULL;
+ _cleanup_free_ gchar *title = NULL;
+ _cleanup_object_unref_ CdIt8 *cmf = NULL;
+ _cleanup_object_unref_ GFile *file = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
+ _cleanup_strv_free_ gchar **lines = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, expected: file");
- goto out;
+ return FALSE;
}
/* get data */
- ret = g_file_get_contents (values[1], &data, NULL, error);
- if (!ret)
- goto out;
+ if (!g_file_get_contents (values[1], &data, NULL, error))
+ return FALSE;
/* parse lines */
array = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_csv2cmf_data_free);
lines = g_strsplit (data, "\n", -1);
norm = g_strtod (values[2], NULL);
for (i = 0; lines[i] != NULL; i++) {
+ _cleanup_strv_free_ gchar **split = NULL;
if (lines[i][0] == '\0')
continue;
if (lines[i][0] == '#')
@@ -452,17 +431,15 @@ cd_util_create_sp (CdUtilPrivate *priv,
} else {
g_printerr ("Ignoring data line: %s", lines[i]);
}
- g_strfreev (split);
}
/* did we get enough data */
if (array->len < 3) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough data in the CSV file");
- goto out;
+ return FALSE;
}
spectrum = cd_spectrum_sized_new (array->len);
@@ -500,15 +477,6 @@ cd_util_create_sp (CdUtilPrivate *priv,
out:
if (spectrum != NULL)
cd_spectrum_free (spectrum);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (cmf != NULL)
- g_object_unref (cmf);
- if (file != NULL)
- g_object_unref (file);
- g_free (data);
- g_free (title);
- g_strfreev (lines);
return ret;
}
@@ -530,9 +498,9 @@ main (int argc, char *argv[])
CdUtilPrivate *priv;
gboolean ret;
gboolean verbose = FALSE;
- gchar *cmd_descriptions = NULL;
- GError *error = NULL;
guint retval = 1;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *cmd_descriptions = NULL;
const GOptionEntry options[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
/* TRANSLATORS: command line option */
@@ -588,7 +556,6 @@ main (int argc, char *argv[])
g_print ("%s: %s\n",
_("Failed to parse arguments"),
error->message);
- g_error_free (error);
goto out;
}
@@ -611,7 +578,6 @@ main (int argc, char *argv[])
} else {
g_print ("%s\n", error->message);
}
- g_error_free (error);
goto out;
}
@@ -624,7 +590,6 @@ out:
g_option_context_free (priv->context);
g_free (priv);
}
- g_free (cmd_descriptions);
return retval;
}
diff --git a/client/cd-util.c b/client/cd-util.c
index 4a821b0..9f45e3d 100644
--- a/client/cd-util.c
+++ b/client/cd-util.c
@@ -29,6 +29,8 @@
#include <stdio.h>
#include <colord/colord.h>
+#include "cd-cleanup.h"
+
#define CD_ERROR 1
#define CD_ERROR_INVALID_ARGUMENTS 0
#define CD_ERROR_NO_SUCH_CMD 1
@@ -119,15 +121,14 @@ cd_util_print_field_time (const gchar *title,
CdUtilPrivate *priv,
gint64 usecs)
{
- gchar *str;
GDateTime *datetime;
+ _cleanup_free_ gchar *str = NULL;
datetime = g_date_time_new_from_unix_utc (usecs / G_USEC_PER_SEC);
/* TRANSLATORS: this is the profile creation date strftime format */
str = g_date_time_format (datetime, _("%B %e %Y, %I:%M:%S %p"));
cd_util_print_field (title, filter_id, priv, str);
g_date_time_unref (datetime);
- g_free (str);
}
/**
@@ -154,10 +155,11 @@ cd_util_show_profile (CdUtilPrivate *priv, CdProfile *profile)
const gchar *tmp;
gchar *str_tmp;
gchar **warnings;
- GHashTable *metadata;
- GList *list, *l;
+ GList *l;
guint i;
guint size;
+ _cleanup_hashtable_unref_ GHashTable *metadata = NULL;
+ _cleanup_list_free_ GList *list = NULL;
/* TRANSLATORS: the internal DBus path */
cd_util_print_field (_("Object Path"),
@@ -245,9 +247,6 @@ cd_util_show_profile (CdUtilPrivate *priv, CdProfile *profile)
size = g_strv_length (warnings);
for (i = 0; i < size; i++)
cd_util_print_field (_("Warning"), "warnings", priv, warnings[i]);
-
- g_list_free (list);
- g_hash_table_unref (metadata);
}
/**
@@ -262,10 +261,11 @@ cd_util_show_device (CdUtilPrivate *priv, CdDevice *device)
gboolean ret;
gchar *str_tmp;
GError *error = NULL;
- GHashTable *metadata;
- GList *list, *l;
+ GList *l;
GPtrArray *profiles;
guint i;
+ _cleanup_hashtable_unref_ GHashTable *metadata = NULL;
+ _cleanup_list_free_ GList *list = NULL;
/* TRANSLATORS: the internal DBus path */
cd_util_print_field (_("Object Path"),
@@ -395,8 +395,6 @@ cd_util_show_device (CdUtilPrivate *priv, CdDevice *device)
cd_util_print_field (_("Metadata"), "metadata", priv, str_tmp);
g_free (str_tmp);
}
- g_list_free (list);
- g_hash_table_unref (metadata);
}
/**
@@ -501,16 +499,16 @@ cd_util_show_sensor (CdUtilPrivate *priv, CdSensor *sensor)
const gchar *tmp;
gboolean ret;
gchar *str_tmp;
- GError *error = NULL;
- GString *caps_str = NULL;
- GHashTable *options = NULL;
GList *l;
- GList *list = NULL;
GMainLoop *loop = NULL;
guint caps;
guint i;
GVariant *value_tmp;
- GHashTable *metadata = NULL;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_hashtable_unref_ GHashTable *metadata = NULL;
+ _cleanup_hashtable_unref_ GHashTable *options = NULL;
+ _cleanup_list_free_ GList *list = NULL;
+ _cleanup_string_free_ GString *caps_str = NULL;
/* TRANSLATORS: the internal DBus path */
cd_util_print_field (_("Object Path"),
@@ -524,7 +522,6 @@ cd_util_show_sensor (CdUtilPrivate *priv, CdSensor *sensor)
if (!ret) {
g_warning ("Failed to lock sensor: %s",
error->message);
- g_error_free (error);
goto out;
}
@@ -646,17 +643,9 @@ cd_util_show_sensor (CdUtilPrivate *priv, CdSensor *sensor)
if (!ret) {
g_warning ("Failed to unlock sensor: %s",
error->message);
- g_error_free (error);
goto out;
}
out:
- if (metadata != NULL)
- g_hash_table_unref (metadata);
- g_list_free (list);
- if (caps_str != NULL)
- g_string_free (caps_str, TRUE);
- if (options != NULL)
- g_hash_table_unref (options);
if (loop != NULL)
g_main_loop_unref (loop);
}
@@ -692,9 +681,9 @@ cd_util_add (GPtrArray *array,
const gchar *description,
CdUtilPrivateCb callback)
{
- gchar **names;
guint i;
CdUtilItem *item;
+ _cleanup_strv_free_ gchar **names = NULL;
g_return_if_fail (name != NULL);
g_return_if_fail (description != NULL);
@@ -716,7 +705,6 @@ cd_util_add (GPtrArray *array,
item->callback = callback;
g_ptr_array_add (array, item);
}
- g_strfreev (names);
}
/**
@@ -771,18 +759,15 @@ cd_util_get_descriptions (GPtrArray *array)
static gboolean
cd_util_run (CdUtilPrivate *priv, const gchar *command, gchar **values, GError **error)
{
- gboolean ret = FALSE;
guint i;
CdUtilItem *item;
- GString *string;
+ _cleanup_string_free_ GString *string = NULL;
/* find command */
for (i = 0; i < priv->cmd_array->len; i++) {
item = g_ptr_array_index (priv->cmd_array, i);
- if (g_strcmp0 (item->name, command) == 0) {
- ret = item->callback (priv, values, error);
- goto out;
- }
+ if (g_strcmp0 (item->name, command) == 0)
+ return item->callback (priv, values, error);
}
/* not found */
@@ -797,9 +782,7 @@ cd_util_run (CdUtilPrivate *priv, const gchar *command, gchar **values, GError *
item->arguments ? item->arguments : "");
}
g_set_error_literal (error, CD_ERROR, CD_ERROR_NO_SUCH_CMD, string->str);
- g_string_free (string, TRUE);
-out:
- return ret;
+ return FALSE;
}
/**
@@ -812,14 +795,14 @@ cd_util_dump (CdUtilPrivate *priv, gchar **values, GError **error)
CdProfile *profile;
const gchar *argv[] = { "sqlite3", "/var/lib/colord/mapping.db", ".dump", NULL };
gboolean ret = TRUE;
- gchar *mapping_db = NULL;
gchar *tmp;
GDateTime *dt;
GError *error_local = NULL;
- GPtrArray *devices = NULL;
- GPtrArray *profiles = NULL;
- GString *str;
guint i;
+ _cleanup_free_ gchar *mapping_db = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *devices = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *profiles = NULL;
+ _cleanup_string_free_ GString *str = NULL;
/* header */
str = g_string_new ("");
@@ -910,12 +893,6 @@ cd_util_dump (CdUtilPrivate *priv, gchar **values, GError **error)
g_free (tmp);
out:
g_date_time_unref (dt);
- g_free (mapping_db);
- g_string_free (str, FALSE);
- if (devices != NULL)
- g_ptr_array_unref (devices);
- if (profiles != NULL)
- g_ptr_array_unref (profiles);
return ret;
}
@@ -926,29 +903,22 @@ static gboolean
cd_util_get_devices (CdUtilPrivate *priv, gchar **values, GError **error)
{
CdDevice *device;
- gboolean ret = TRUE;
- GPtrArray *array = NULL;
guint i;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
/* execute sync method */
array = cd_client_get_devices_sync (priv->client, NULL, error);
- if (array == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (array == NULL)
+ return FALSE;
for (i = 0; i < array->len; i++) {
device = g_ptr_array_index (array, i);
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
cd_util_show_device (priv, device);
if (i != array->len - 1 && !priv->value_only)
g_print ("\n");
}
-out:
- if (array != NULL)
- g_ptr_array_unref (array);
- return ret;
+ return TRUE;
}
/**
@@ -958,19 +928,17 @@ static gboolean
cd_util_get_devices_by_kind (CdUtilPrivate *priv, gchar **values, GError **error)
{
CdDevice *device;
- gboolean ret = TRUE;
- GPtrArray *array = NULL;
guint i;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device kind "
"e.g. 'printer'");
- goto out;
+ return FALSE;
}
/* execute sync method */
@@ -978,23 +946,17 @@ cd_util_get_devices_by_kind (CdUtilPrivate *priv, gchar **values, GError **error
cd_device_kind_from_string (values[0]),
NULL,
error);
- if (array == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (array == NULL)
+ return FALSE;
for (i = 0; i < array->len; i++) {
device = g_ptr_array_index (array, i);
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
cd_util_show_device (priv, device);
if (i != array->len - 1 && !priv->value_only)
g_print ("\n");
}
-out:
- if (array != NULL)
- g_ptr_array_unref (array);
- return ret;
+ return TRUE;
}
/**
@@ -1004,29 +966,22 @@ static gboolean
cd_util_get_profiles (CdUtilPrivate *priv, gchar **values, GError **error)
{
CdProfile *profile;
- gboolean ret = TRUE;
- GPtrArray *array = NULL;
guint i;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
/* execute sync method */
array = cd_client_get_profiles_sync (priv->client, NULL, error);
- if (array == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (array == NULL)
+ return FALSE;
for (i = 0; i < array->len; i++) {
profile = g_ptr_array_index (array, i);
- ret = cd_profile_connect_sync (profile, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_profile_connect_sync (profile, NULL, error))
+ return FALSE;
cd_util_show_profile (priv, profile);
if (i != array->len - 1 && !priv->value_only)
g_print ("\n");
}
-out:
- if (array != NULL)
- g_ptr_array_unref (array);
- return ret;
+ return TRUE;
}
/**
@@ -1036,36 +991,28 @@ static gboolean
cd_util_get_sensors (CdUtilPrivate *priv, gchar **values, GError **error)
{
CdSensor *sensor;
- gboolean ret = TRUE;
- GPtrArray *array = NULL;
guint i;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
/* execute sync method */
array = cd_client_get_sensors_sync (priv->client, NULL, error);
- if (array == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (array == NULL)
+ return FALSE;
if (array->len == 0) {
- ret = FALSE;
/* TRANSLATORS: the user does not have a colorimeter attached */
g_set_error_literal (error, CD_ERROR, CD_ERROR_INVALID_ARGUMENTS,
_("There are no supported sensors attached"));
- goto out;
+ return FALSE;
}
for (i = 0; i < array->len; i++) {
sensor = g_ptr_array_index (array, i);
- ret = cd_sensor_connect_sync (sensor, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_sensor_connect_sync (sensor, NULL, error))
+ return FALSE;
cd_util_show_sensor (priv, sensor);
if (i != array->len - 1 && !priv->value_only)
g_print ("\n");
}
-out:
- if (array != NULL)
- g_ptr_array_unref (array);
- return ret;
+ return TRUE;
}
/**
@@ -1075,48 +1022,35 @@ static gboolean
cd_util_sensor_lock (CdUtilPrivate *priv, gchar **values, GError **error)
{
CdSensor *sensor;
- gboolean ret = TRUE;
GMainLoop *loop = NULL;
- GPtrArray *array = NULL;
guint i;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
/* execute sync method */
array = cd_client_get_sensors_sync (priv->client, NULL, error);
- if (array == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (array == NULL)
+ return FALSE;
if (array->len == 0) {
- ret = FALSE;
/* TRANSLATORS: the user does not have a colorimeter attached */
g_set_error_literal (error, CD_ERROR, CD_ERROR_INVALID_ARGUMENTS,
_("There are no supported sensors attached"));
- goto out;
+ return FALSE;
}
for (i = 0; i < array->len; i++) {
sensor = g_ptr_array_index (array, i);
-
- ret = cd_sensor_connect_sync (sensor, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_sensor_connect_sync (sensor, NULL, error))
+ return FALSE;
/* lock */
- ret = cd_sensor_lock_sync (sensor,
- NULL,
- error);
- if (!ret)
- goto out;
+ if (!cd_sensor_lock_sync (sensor, NULL, error))
+ return FALSE;
}
/* spin */
loop = g_main_loop_new (NULL, TRUE);
g_main_loop_run (loop);
-out:
- if (loop != NULL)
- g_main_loop_unref (loop);
- if (array != NULL)
- g_ptr_array_unref (array);
- return ret;
+ g_main_loop_unref (loop);
+ return TRUE;
}
/**
@@ -1128,43 +1062,37 @@ cd_util_get_sensor_reading (CdUtilPrivate *priv, gchar **values, GError **error)
CdColorXYZ *xyz;
CdSensorCap cap;
CdSensor *sensor;
- gboolean ret = TRUE;
GError *error_local = NULL;
- GPtrArray *array = NULL;
guint i;
guint j;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device type "
"e.g. 'lcd'");
- goto out;
+ return FALSE;
}
/* execute sync method */
array = cd_client_get_sensors_sync (priv->client, NULL, error);
- if (array == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (array == NULL)
+ return FALSE;
if (array->len == 0) {
- ret = FALSE;
/* TRANSLATORS: the user does not have a colorimeter attached */
g_set_error_literal (error, CD_ERROR, CD_ERROR_INVALID_ARGUMENTS,
_("There are no supported sensors attached"));
- goto out;
+ return FALSE;
}
cap = cd_sensor_cap_from_string (values[0]);
for (i = 0; i < array->len; i++) {
sensor = g_ptr_array_index (array, i);
- ret = cd_sensor_connect_sync (sensor, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_sensor_connect_sync (sensor, NULL, error))
+ return FALSE;
/* TRANSLATORS: this is the sensor title */
g_print ("%s: %s - %s\n", _("Sensor"),
@@ -1172,11 +1100,8 @@ cd_util_get_sensor_reading (CdUtilPrivate *priv, gchar **values, GError **error)
cd_sensor_get_model (sensor));
/* lock */
- ret = cd_sensor_lock_sync (sensor,
- NULL,
- error);
- if (!ret)
- goto out;
+ if (!cd_sensor_lock_sync (sensor, NULL, error))
+ return FALSE;
/* get 3 samples sync */
for (j = 1; j < 4; j++) {
@@ -1206,8 +1131,7 @@ cd_util_get_sensor_reading (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
g_propagate_error (error,
error_local);
- ret = FALSE;
- goto out;
+ return FALSE;
}
}
@@ -1219,16 +1143,10 @@ cd_util_get_sensor_reading (CdUtilPrivate *priv, gchar **values, GError **error)
}
/* unlock */
- ret = cd_sensor_unlock_sync (sensor,
- NULL,
- error);
- if (!ret)
- goto out;
+ if (!cd_sensor_unlock_sync (sensor, NULL, error))
+ return FALSE;
}
-out:
- if (array != NULL)
- g_ptr_array_unref (array);
- return ret;
+ return TRUE;
}
/**
@@ -1238,36 +1156,31 @@ static gboolean
cd_util_sensor_set_options (CdUtilPrivate *priv, gchar **values, GError **error)
{
CdSensor *sensor;
- gboolean ret = TRUE;
gchar *endptr = NULL;
gdouble val;
- GHashTable *options = NULL;
- GPtrArray *array = NULL;
guint i;
+ _cleanup_hashtable_unref_ GHashTable *options = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected key value "
"e.g. 'remote-profile-hash' 'deadbeef'");
- goto out;
+ return FALSE;
}
/* execute sync method */
array = cd_client_get_sensors_sync (priv->client, NULL, error);
- if (array == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (array == NULL)
+ return FALSE;
if (array->len == 0) {
- ret = FALSE;
/* TRANSLATORS: the user does not have a colorimeter attached */
g_set_error_literal (error, CD_ERROR, CD_ERROR_INVALID_ARGUMENTS,
_("There are no supported sensors attached"));
- goto out;
+ return FALSE;
}
/* prepare options for each sensor
@@ -1287,16 +1200,12 @@ cd_util_sensor_set_options (CdUtilPrivate *priv, gchar **values, GError **error)
for (i = 0; i < array->len; i++) {
sensor = g_ptr_array_index (array, i);
- ret = cd_sensor_connect_sync (sensor, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_sensor_connect_sync (sensor, NULL, error))
+ return FALSE;
/* lock */
- ret = cd_sensor_lock_sync (sensor,
- NULL,
- error);
- if (!ret)
- goto out;
+ if (!cd_sensor_lock_sync (sensor, NULL, error))
+ return FALSE;
/* TRANSLATORS: this is the sensor title */
g_print ("%s: %s - %s\n", _("Sensor"),
@@ -1304,26 +1213,14 @@ cd_util_sensor_set_options (CdUtilPrivate *priv, gchar **values, GError **error)
cd_sensor_get_model (sensor));
/* set the options set */
- ret = cd_sensor_set_options_sync (sensor,
- options,
- NULL,
- error);
- if (!ret)
- goto out;
+ if (!cd_sensor_set_options_sync (sensor, options, NULL, error))
+ return FALSE;
/* unlock */
- ret = cd_sensor_unlock_sync (sensor,
- NULL,
- error);
- if (!ret)
- goto out;
+ if (!cd_sensor_unlock_sync (sensor, NULL, error))
+ return FALSE;
}
-out:
- if (options != NULL)
- g_hash_table_unref (options);
- if (array != NULL)
- g_ptr_array_unref (array);
- return ret;
+ return TRUE;
}
/**
@@ -1332,20 +1229,18 @@ out:
static gboolean
cd_util_create_device (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- gboolean ret = TRUE;
guint mask;
- GHashTable *device_props = NULL;
+ _cleanup_hashtable_unref_ GHashTable *device_props = NULL;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 3) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device id, scope, kind "
"e.g. 'epson-stylus-800 disk display'");
- goto out;
+ return FALSE;
}
/* execute sync method */
@@ -1360,21 +1255,13 @@ cd_util_create_device (CdUtilPrivate *priv, gchar **values, GError **error)
device_props,
NULL,
error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
g_print ("Created device:\n");
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
cd_util_show_device (priv, device);
-out:
- if (device_props != NULL)
- g_hash_table_unref (device_props);
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ return TRUE;
}
/**
@@ -1383,35 +1270,27 @@ out:
static gboolean
cd_util_find_device (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device id "
"e.g. 'epson-stylus-800'");
- goto out;
+ return FALSE;
}
/* execute sync method */
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (device == NULL)
+ return FALSE;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
cd_util_show_device (priv, device);
-out:
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ return TRUE;
}
/**
@@ -1420,18 +1299,16 @@ out:
static gboolean
cd_util_find_device_by_property (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected key value "
"e.g. 'XRANDR_name' 'lvds'");
- goto out;
+ return FALSE;
}
/* execute sync method */
@@ -1440,18 +1317,12 @@ cd_util_find_device_by_property (CdUtilPrivate *priv, gchar **values, GError **e
values[1],
NULL,
error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (device == NULL)
+ return FALSE;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
cd_util_show_device (priv, device);
-out:
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ return TRUE;
}
/**
@@ -1460,35 +1331,27 @@ out:
static gboolean
cd_util_find_profile (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected profile id "
"e.g. 'epson-rgb'");
- goto out;
+ return FALSE;
}
/* execute sync method */
profile = cd_client_find_profile_sync (priv->client, values[0],
NULL, error);
- if (profile == NULL) {
- ret = FALSE;
- goto out;
- }
- ret = cd_profile_connect_sync (profile, NULL, error);
- if (!ret)
- goto out;
+ if (profile == NULL)
+ return FALSE;
+ if (!cd_profile_connect_sync (profile, NULL, error))
+ return FALSE;
cd_util_show_profile (priv, profile);
-out:
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return TRUE;
}
/**
@@ -1497,35 +1360,27 @@ out:
static gboolean
cd_util_find_profile_by_filename (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected profile filename");
- goto out;
+ return FALSE;
}
/* execute sync method */
profile = cd_client_find_profile_by_filename_sync (priv->client,
values[0],
NULL, error);
- if (profile == NULL) {
- ret = FALSE;
- goto out;
- }
- ret = cd_profile_connect_sync (profile, NULL, error);
- if (!ret)
- goto out;
+ if (profile == NULL)
+ return FALSE;
+ if (!cd_profile_connect_sync (profile, NULL, error))
+ return FALSE;
cd_util_show_profile (priv, profile);
-out:
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return TRUE;
}
/**
@@ -1534,18 +1389,16 @@ out:
static gboolean
cd_util_get_standard_space (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected standard space "
"e.g. 'adobe-rgb'");
- goto out;
+ return FALSE;
}
/* execute sync method */
@@ -1553,18 +1406,12 @@ cd_util_get_standard_space (CdUtilPrivate *priv, gchar **values, GError **error)
cd_standard_space_from_string (values[0]),
NULL,
error);
- if (profile == NULL) {
- ret = FALSE;
- goto out;
- }
- ret = cd_profile_connect_sync (profile, NULL, error);
- if (!ret)
- goto out;
+ if (profile == NULL)
+ return FALSE;
+ if (!cd_profile_connect_sync (profile, NULL, error))
+ return FALSE;
cd_util_show_profile (priv, profile);
-out:
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return TRUE;
}
/**
@@ -1573,38 +1420,30 @@ out:
static gboolean
cd_util_create_profile (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
guint mask;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected profile id, scope "
"e.g. 'epson-rgb disk'");
- goto out;
+ return FALSE;
}
/* execute sync method */
mask = cd_object_scope_from_string (values[1]);
profile = cd_client_create_profile_sync (priv->client, values[0],
mask, NULL, NULL, error);
- if (profile == NULL) {
- ret = FALSE;
- goto out;
- }
- ret = cd_profile_connect_sync (profile, NULL, error);
- if (!ret)
- goto out;
+ if (profile == NULL)
+ return FALSE;
+ if (!cd_profile_connect_sync (profile, NULL, error))
+ return FALSE;
g_print ("Created profile:\n");
cd_util_show_profile (priv, profile);
-out:
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return TRUE;
}
/**
@@ -1613,19 +1452,17 @@ out:
static gboolean
cd_util_device_add_profile (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path, profile path "
"e.g. '/org/device/foo /org/profile/bar'");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -1634,14 +1471,11 @@ cd_util_device_add_profile (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
/* find the profile */
if (g_variant_is_object_path (values[1])) {
@@ -1649,24 +1483,14 @@ cd_util_device_add_profile (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
profile = cd_client_find_profile_sync (priv->client, values[1],
NULL, error);
- if (profile == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (profile == NULL)
+ return FALSE;
}
- ret = cd_device_add_profile_sync (device,
- CD_DEVICE_RELATION_HARD,
- profile,
- NULL,
- error);
- if (!ret)
- goto out;
-out:
- if (device != NULL)
- g_object_unref (device);
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return cd_device_add_profile_sync (device,
+ CD_DEVICE_RELATION_HARD,
+ profile,
+ NULL,
+ error);
}
/**
@@ -1675,19 +1499,17 @@ out:
static gboolean
cd_util_device_make_profile_default (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path, profile path "
"e.g. '/org/device/foo /org/profile/bar'");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -1696,14 +1518,11 @@ cd_util_device_make_profile_default (CdUtilPrivate *priv, gchar **values, GError
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
/* find the profile */
if (g_variant_is_object_path (values[1])) {
@@ -1711,21 +1530,10 @@ cd_util_device_make_profile_default (CdUtilPrivate *priv, gchar **values, GError
} else {
profile = cd_client_find_profile_sync (priv->client, values[1],
NULL, error);
- if (profile == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (profile == NULL)
+ return FALSE;
}
- ret = cd_device_make_profile_default_sync (device, profile,
- NULL, error);
- if (!ret)
- goto out;
-out:
- if (device != NULL)
- g_object_unref (device);
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return cd_device_make_profile_default_sync (device, profile, NULL, error);
}
/**
@@ -1734,18 +1542,16 @@ out:
static gboolean
cd_util_delete_device (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
- CdDevice *device = NULL;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path "
"e.g. '/org/devices/foo'");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -1754,19 +1560,10 @@ cd_util_delete_device (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_client_delete_device_sync (priv->client, device,
- NULL, error);
- if (!ret)
- goto out;
-out:
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ return cd_client_delete_device_sync (priv->client, device, NULL, error);
}
/**
@@ -1775,18 +1572,16 @@ out:
static gboolean
cd_util_delete_profile (CdUtilPrivate *priv, gchar **values, GError **error)
{
- gboolean ret = TRUE;
- CdProfile *profile = NULL;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected profile path "
"e.g. '/org/profiles/bar'");
- goto out;
+ return FALSE;
}
/* find the profile */
@@ -1796,16 +1591,9 @@ cd_util_delete_profile (CdUtilPrivate *priv, gchar **values, GError **error)
profile = cd_client_find_profile_sync (priv->client, values[0],
NULL, error);
if (profile == NULL)
- goto out;
+ return FALSE;
}
- ret = cd_client_delete_profile_sync (priv->client, profile,
- NULL, error);
- if (!ret)
- goto out;
-out:
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return cd_client_delete_profile_sync (priv->client, profile, NULL, error);
}
/**
@@ -1814,18 +1602,16 @@ out:
static gboolean
cd_util_profile_set_property (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
if (g_strv_length (values) < 3) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected profile path key value "
"e.g. '/org/profile/foo qualifier RGB.Matte.300dpi'");
- goto out;
+ return FALSE;
}
/* find the profile */
@@ -1835,22 +1621,15 @@ cd_util_profile_set_property (CdUtilPrivate *priv, gchar **values, GError **erro
profile = cd_client_find_profile_sync (priv->client, values[0],
NULL, error);
if (profile == NULL)
- goto out;
+ return FALSE;
}
- ret = cd_profile_connect_sync (profile, NULL, error);
- if (!ret)
- goto out;
- ret = cd_profile_set_property_sync (profile,
- values[1],
- values[2],
- NULL,
- error);
- if (!ret)
- goto out;
-out:
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ if (!cd_profile_connect_sync (profile, NULL, error))
+ return FALSE;
+ return cd_profile_set_property_sync (profile,
+ values[1],
+ values[2],
+ NULL,
+ error);
}
/**
@@ -1859,18 +1638,16 @@ out:
static gboolean
cd_util_device_set_model (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path, model "
"e.g. '/org/devices/bar \"Stylus 800\"'");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -1879,22 +1656,12 @@ cd_util_device_set_model (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
- ret = cd_device_set_model_sync (device, values[1],
- NULL, error);
- if (!ret)
- goto out;
-out:
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
+ return cd_device_set_model_sync (device, values[1], NULL, error);
}
/**
@@ -1903,17 +1670,15 @@ out:
static gboolean
cd_util_device_set_enabled (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path, True|False");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -1922,24 +1687,15 @@ cd_util_device_set_enabled (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
- ret = cd_device_set_enabled_sync (device,
- g_strcmp0 (values[1], "True") == 0,
- NULL,
- error);
- if (!ret)
- goto out;
-out:
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
+ return cd_device_set_enabled_sync (device,
+ g_strcmp0 (values[1], "True") == 0,
+ NULL,
+ error);
}
/**
@@ -1950,19 +1706,17 @@ cd_util_device_get_default_profile (CdUtilPrivate *priv,
gchar **values,
GError **error)
{
- CdDevice *device = NULL;
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path "
"e.g. '/org/devices/bar'");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -1971,33 +1725,23 @@ cd_util_device_get_default_profile (CdUtilPrivate *priv,
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
profile = cd_device_get_default_profile (device);
if (profile == NULL) {
- ret = FALSE;
g_set_error (error,
CD_ERROR, CD_ERROR_INVALID_ARGUMENTS,
"There is no assigned profile for %s",
values[0]);
- goto out;
+ return FALSE;
}
- ret = cd_profile_connect_sync (profile, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_profile_connect_sync (profile, NULL, error))
+ return FALSE;
cd_util_show_profile (priv, profile);
-out:
- if (device != NULL)
- g_object_unref (device);
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return TRUE;
}
/**
@@ -2006,18 +1750,16 @@ out:
static gboolean
cd_util_device_set_vendor (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path, vendor "
"e.g. '/org/devices/bar Epson'");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -2026,22 +1768,12 @@ cd_util_device_set_vendor (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
- ret = cd_device_set_vendor_sync (device, values[1],
- NULL, error);
- if (!ret)
- goto out;
-out:
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
+ return cd_device_set_vendor_sync (device, values[1], NULL, error);
}
/**
@@ -2050,18 +1782,16 @@ out:
static gboolean
cd_util_device_set_serial (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path, serial "
"e.g. '/org/devices/bar 00001234'");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -2070,22 +1800,12 @@ cd_util_device_set_serial (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
- ret = cd_device_set_serial_sync (device, values[1],
- NULL, error);
- if (!ret)
- goto out;
-out:
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
+ return cd_device_set_serial_sync (device, values[1], NULL, error);
}
/**
@@ -2094,18 +1814,16 @@ out:
static gboolean
cd_util_device_set_kind (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path, kind "
"e.g. '/org/devices/bar printer'");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -2114,22 +1832,12 @@ cd_util_device_set_kind (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
- ret = cd_device_set_kind_sync (device, cd_device_kind_from_string (values[1]),
- NULL, error);
- if (!ret)
- goto out;
-out:
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
+ return cd_device_set_kind_sync (device, cd_device_kind_from_string (values[1]), NULL, error);
}
/**
@@ -2138,31 +1846,28 @@ out:
static gboolean
cd_util_device_inhibit (CdUtilPrivate *priv, gchar **values, GError **error)
{
- CdDevice *device = NULL;
- gboolean ret = TRUE;
GMainLoop *loop = NULL;
gint timeout;
+ _cleanup_object_unref_ CdDevice *device = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path timeout (use 0 for 'never') "
"e.g. '/org/devices/epson-800' 60");
- goto out;
+ return FALSE;
}
/* check timeout is valid */
timeout = atoi (values[1]);
if (timeout < 0) {
- ret = FALSE;
g_set_error (error,
CD_ERROR, CD_ERROR_INVALID_ARGUMENTS,
"Not a valid timeout: %s",
values[1]);
- goto out;
+ return FALSE;
}
/* find the device */
@@ -2171,17 +1876,13 @@ cd_util_device_inhibit (CdUtilPrivate *priv, gchar **values, GError **error)
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
- ret = cd_device_profiling_inhibit_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
+ if (!cd_device_profiling_inhibit_sync (device, NULL, error))
+ return FALSE;
/* wait for ctrl-c, as inhibit will be destroyed when the
* colormgr tool is finished */
@@ -2192,12 +1893,8 @@ cd_util_device_inhibit (CdUtilPrivate *priv, gchar **values, GError **error)
loop);
}
g_main_loop_run (loop);
-out:
- if (loop != NULL)
- g_main_loop_unref (loop);
- if (device != NULL)
- g_object_unref (device);
- return ret;
+ g_main_loop_unref (loop);
+ return TRUE;
}
/**
@@ -2208,19 +1905,17 @@ cd_util_device_get_profile_for_qualifiers (CdUtilPrivate *priv,
gchar **values,
GError **error)
{
- CdDevice *device = NULL;
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ CdDevice *device = NULL;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
if (g_strv_length (values) < 2) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, "
"expected device path, qualifier "
"e.g. '/org/devices/bar *.*.300dpi'");
- goto out;
+ return FALSE;
}
/* find the device */
@@ -2229,32 +1924,21 @@ cd_util_device_get_profile_for_qualifiers (CdUtilPrivate *priv,
} else {
device = cd_client_find_device_sync (priv->client, values[0],
NULL, error);
- if (device == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (device == NULL)
+ return FALSE;
}
- ret = cd_device_connect_sync (device, NULL, error);
- if (!ret)
- goto out;
+ if (!cd_device_connect_sync (device, NULL, error))
+ return FALSE;
profile = cd_device_get_profile_for_qualifiers_sync (device,
(const gchar **) &values[1],
NULL,
error);
- if (profile == NULL) {
- ret = FALSE;
- goto out;
- }
- ret = cd_profile_connect_sync (profile, NULL, error);
- if (!ret)
- goto out;
+ if (profile == NULL)
+ return FALSE;
+ if (!cd_profile_connect_sync (profile, NULL, error))
+ return FALSE;
cd_util_show_profile (priv, profile);
-out:
- if (device != NULL)
- g_object_unref (device);
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return TRUE;
}
/**
@@ -2265,17 +1949,15 @@ cd_util_import_profile (CdUtilPrivate *priv,
gchar **values,
GError **error)
{
- CdProfile *profile = NULL;
- gboolean ret = TRUE;
- GFile *file = NULL;
+ _cleanup_object_unref_ CdProfile *profile = NULL;
+ _cleanup_object_unref_ GFile *file = NULL;
if (g_strv_length (values) < 1) {
- ret = FALSE;
g_set_error_literal (error,
CD_ERROR,
CD_ERROR_INVALID_ARGUMENTS,
"Not enough arguments, expected: file");
- goto out;
+ return FALSE;
}
/* import the profile */
@@ -2284,20 +1966,12 @@ cd_util_import_profile (CdUtilPrivate *priv,
file,
NULL,
error);
- if (profile == NULL) {
- ret = FALSE;
- goto out;
- }
- ret = cd_profile_connect_sync (profile, NULL, error);
- if (!ret)
- goto out;
+ if (profile == NULL)
+ return FALSE;
+ if (!cd_profile_connect_sync (profile, NULL, error))
+ return FALSE;
cd_util_show_profile (priv, profile);
-out:
- if (file != NULL)
- g_object_unref (file);
- if (profile != NULL)
- g_object_unref (profile);
- return ret;
+ return TRUE;
}
/**
@@ -2320,10 +1994,10 @@ main (int argc, char *argv[])
gboolean value_only = FALSE;
gboolean verbose = FALSE;
gboolean version = FALSE;
- gchar *cmd_descriptions = NULL;
- gchar *filter = NULL;
- GError *error = NULL;
guint retval = 1;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *cmd_descriptions = NULL;
+ _cleanup_free_ gchar *filter = NULL;
const GOptionEntry options[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
/* TRANSLATORS: command line option */
@@ -2541,10 +2215,8 @@ main (int argc, char *argv[])
ret = g_option_context_parse (priv->context, &argc, &argv, &error);
if (!ret) {
/* TRANSLATORS: the user didn't read the man page */
- g_print ("%s: %s\n",
- _("Failed to parse arguments"),
+ g_print ("%s: %s\n", _("Failed to parse arguments"),
error->message);
- g_error_free (error);
goto out;
}
@@ -2568,7 +2240,6 @@ main (int argc, char *argv[])
/* TRANSLATORS: no colord available */
g_print ("%s %s\n", _("No connection to colord:"),
error->message);
- g_error_free (error);
goto out;
}
@@ -2589,14 +2260,12 @@ main (int argc, char *argv[])
ret = cd_util_run (priv, argv[1], (gchar**) &argv[2], &error);
if (!ret) {
if (g_error_matches (error, CD_ERROR, CD_ERROR_NO_SUCH_CMD)) {
- gchar *tmp;
+ _cleanup_free_ gchar *tmp = NULL;
tmp = g_option_context_get_help (priv->context, TRUE, NULL);
g_print ("%s", tmp);
- g_free (tmp);
} else {
g_print ("%s\n", error->message);
}
- g_error_free (error);
goto out;
}
@@ -2612,8 +2281,6 @@ out:
g_option_context_free (priv->context);
g_free (priv);
}
- g_free (filter);
- g_free (cmd_descriptions);
return retval;
}