[frogr] Use g_autoptr, g_auto and g_autofree whenever possible
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Use g_autoptr, g_auto and g_autofree whenever possible
- Date: Wed, 27 Dec 2017 01:18:28 +0000 (UTC)
commit 8345a55d2c1e161009c52b94ffd1a08d04a4ead3
Author: Mario Sanchez Prada <msanchez gnome org>
Date: Wed Dec 27 00:41:44 2017 +0100
Use g_autoptr, g_auto and g_autofree whenever possible
This will make the code more compact and less prone to leaking memory,
by requiring to bump the required versions of GTK+ and JSON-GLib.
NEWS | 1 +
meson.build | 4 +-
src/examples/example.c | 68 +++++----------
src/flicksoup/fsp-parser.c | 15 +--
src/flicksoup/fsp-session.c | 169 +++++++++++--------------------------
src/frogr-about-dialog.c | 11 +--
src/frogr-add-tags-dialog.c | 8 +--
src/frogr-add-to-group-dialog.c | 16 +---
src/frogr-add-to-set-dialog.c | 16 +---
src/frogr-auth-dialog.c | 10 +--
src/frogr-config.c | 38 +++------
src/frogr-controller.c | 147 ++++++++++----------------------
src/frogr-create-new-set-dialog.c | 20 ++---
src/frogr-details-dialog.c | 52 ++++--------
src/frogr-file-loader.c | 97 ++++++---------------
src/frogr-live-entry.c | 23 ++----
src/frogr-main-view.c | 125 ++++++++-------------------
src/frogr-model.c | 25 ++----
src/frogr-photoset.c | 3 +-
src/frogr-picture.c | 35 ++------
src/frogr-settings-dialog.c | 6 +-
src/frogr-util.c | 44 +++-------
src/main.c | 10 +--
23 files changed, 284 insertions(+), 659 deletions(-)
---
diff --git a/NEWS b/NEWS
index e78f957..67a8e2c 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@
* Migrated to the meson and ninja, removed all the autotools files.
* Fixed integration with GNOME Software (appstream data).
* Fixed errors loading images from certain cameras / phones (#768639, #678241).
+ * Raised versions for GTK+ (to 3.16) and JSON-GLib (to 1.2), for g_autoptr.
New and updated translations:
diff --git a/meson.build b/meson.build
index c8d931b..3f0214e 100644
--- a/meson.build
+++ b/meson.build
@@ -24,12 +24,12 @@ frogr_conf.set_quoted('LOCALEDIR', join_paths(prefix, localedir))
compiler = meson.get_compiler('c')
# Dependencies
-gtk_ver = '3.4'
+gtk_ver = '3.16'
glib_ver = '2.44'
soup_ver = '2.34'
exif_ver = '0.6.14'
xml2_ver = '2.6.8'
-json_glib_ver = '0.12'
+json_glib_ver = '1.2'
gcrypt_ver = '1.5.0'
glib = dependency('glib-2.0', version: '>=@0@'.format(glib_ver))
diff --git a/src/examples/example.c b/src/examples/example.c
index 0474b1c..ceb7172 100644
--- a/src/examples/example.c
+++ b/src/examples/example.c
@@ -77,7 +77,7 @@ upload_cb (GObject *object,
gpointer source_func)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
g_free (uploaded_photo_id);
uploaded_photo_id = fsp_session_upload_finish (session, res, &error);
@@ -85,7 +85,6 @@ upload_cb (GObject *object,
if (error != NULL)
{
g_print ("Error uploading picture: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -130,14 +129,13 @@ added_to_group_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean result = FALSE;
result = fsp_session_add_to_group_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error creating group: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -152,14 +150,13 @@ get_groups_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
- GSList *groups_list = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GSList) groups_list = NULL;
groups_list = fsp_session_get_groups_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error getting groups: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -203,8 +200,6 @@ get_groups_cb (GObject *object,
FSP_SEARCH_SCOPE_NONE,
NULL, upload_cb,
(gpointer) get_groups_cb);
-
- g_slist_free (groups_list);
}
}
@@ -214,14 +209,13 @@ added_to_photoset_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean result = FALSE;
result = fsp_session_add_to_photoset_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error adding to photoset: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -245,14 +239,13 @@ photoset_created_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
created_photoset_id =
fsp_session_create_photoset_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error creating photoset: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -285,14 +278,13 @@ get_photosets_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
- GSList *photosets_list =
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GSList) photosets_list =
fsp_session_get_photosets_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error getting photosets: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -325,7 +317,6 @@ get_photosets_cb (GObject *object,
"Photoset's description\nasdasda",
uploaded_photo_id,
NULL, photoset_created_cb, NULL);
- g_slist_free (photosets_list);
}
}
@@ -335,14 +326,13 @@ photo_get_info_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
FspDataPhotoInfo *photo_info =
fsp_session_get_info_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error uploading picture: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -387,14 +377,13 @@ set_date_posted_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean result = FALSE;
result = fsp_session_set_date_posted_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error setting the date posted: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -418,20 +407,19 @@ get_location_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
FspDataLocation *location = NULL;
location = fsp_session_get_location_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error getting location: %s\n", error->message);
- g_error_free (error);
}
else
{
GDateTime *date_now = NULL;
GDateTime *date = NULL;
- gchar* date_str = NULL;
+ g_autofree gchar* date_str = NULL;
g_print ("[get_location_cb]::Success! Location got:\n");
g_print ("[get_location_cb]::\tLatitude: %g\n", location->latitude);
@@ -450,7 +438,6 @@ get_location_cb (GObject *object,
fsp_session_set_date_posted (session, uploaded_photo_id, date, NULL,
set_date_posted_cb, NULL);
- g_free (date_str);
g_date_time_unref (date);
g_date_time_unref (date_now);
@@ -465,14 +452,13 @@ set_location_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean result = FALSE;
result = fsp_session_set_location_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error setting location: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -496,14 +482,13 @@ set_license_cb (GObject *object,
gpointer user_data)
{
FspSession *session = FSP_SESSION (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean result = FALSE;
result = fsp_session_set_license_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error setting license: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -538,14 +523,13 @@ void
get_tags_list_cb (GObject *object, GAsyncResult *res, gpointer unused)
{
FspSession* session = FSP_SESSION (object);
- GSList *tags_list = NULL;
- GError *error = NULL;
+ g_autoptr(GSList) tags_list = NULL;
+ g_autoptr(GError) error = NULL;
tags_list = fsp_session_get_tags_list_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error retrieving tags: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -561,7 +545,6 @@ get_tags_list_cb (GObject *object, GAsyncResult *res, gpointer unused)
g_print ("[get_tags_list_cb]::\tTag: %s\n", tag);
g_free (tag);
}
- g_slist_free (tags_list);
/* Make a pause before continuing */
g_print ("Press ENTER to continue...\n\n");
@@ -594,13 +577,12 @@ get_upload_status_cb (GObject *object, GAsyncResult *res, gpointer unused)
{
FspSession* session = FSP_SESSION (object);
FspDataUploadStatus *upload_status = NULL;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
upload_status = fsp_session_get_upload_status_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error retrieving upload status: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -639,13 +621,12 @@ check_auth_info_cb (GObject *object, GAsyncResult *res, gpointer unused)
{
FspSession* session = FSP_SESSION (object);
FspDataAuthToken *auth_token = NULL;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
auth_token = fsp_session_check_auth_info_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error checking authorization information: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -677,13 +658,12 @@ complete_auth_cb (GObject *object,
{
FspSession* session = FSP_SESSION (object);
FspDataAuthToken *auth_token = NULL;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
auth_token = fsp_session_complete_auth_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error completing authorization: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -715,13 +695,12 @@ get_auth_url_cb (GObject *object,
gpointer user_data)
{
FspSession* session = FSP_SESSION (object);
- GError *error = NULL;
- gchar *auth_url = fsp_session_get_auth_url_finish (session, res, &error);
+ g_autoptr(GError) error = NULL;
+ g_autofree gchar *auth_url = fsp_session_get_auth_url_finish (session, res, &error);
if (error != NULL)
{
g_print ("Error getting auth URL: %s\n", error->message);
- g_error_free (error);
}
else
{
@@ -734,19 +713,16 @@ get_auth_url_cb (GObject *object,
g_print ("\nEnter the verification code and press ENTER to continue: ");
if (fgets(buffer, 12, stdin))
{
- gchar *verifier = NULL;
+ g_autofree gchar *verifier = NULL;
verifier = encode_uri (buffer);
/* Continue finishing the authorization */
g_print ("Finishing authorization...\n");
fsp_session_complete_auth (session, verifier, NULL, complete_auth_cb, NULL);
- g_free (verifier);
}
else
g_print ("Authorization failed. Can't continue.\n");
-
- g_free (auth_url);
}
}
diff --git a/src/flicksoup/fsp-parser.c b/src/flicksoup/fsp-parser.c
index 999d38e..89d10e0 100644
--- a/src/flicksoup/fsp-parser.c
+++ b/src/flicksoup/fsp-parser.c
@@ -234,7 +234,7 @@ _parse_error_from_node (xmlNode *error_node,
FspError error = FSP_ERROR_UNKNOWN;
xmlChar *code_str = NULL;
xmlChar *msg = NULL;
- gchar *error_msg = NULL;
+ g_autofree gchar *error_msg = NULL;
gint code;
GError *err = NULL;
@@ -257,7 +257,6 @@ _parse_error_from_node (xmlNode *error_node,
xmlFree (code_str);
xmlFree (msg);
- g_free (error_msg);
return err;
}
@@ -1246,8 +1245,8 @@ fsp_parser_get_request_token (FspParser *self,
GError **error)
{
FspDataAuthToken *auth_token = NULL;
- gchar *response_str = NULL;
- gchar **response_array = NULL;
+ g_autofree gchar *response_str = NULL;
+ g_auto(GStrv) response_array = NULL;
gint i = 0;
g_return_val_if_fail (FSP_IS_PARSER (self), NULL);
@@ -1257,7 +1256,6 @@ fsp_parser_get_request_token (FspParser *self,
auth_token = FSP_DATA_AUTH_TOKEN (fsp_data_new (FSP_AUTH_TOKEN));
response_str = g_strndup (buffer, buf_size);
response_array = g_strsplit (response_str, "&", -1);
- g_free (response_str);
for (i = 0; response_array[i]; i++)
{
@@ -1267,7 +1265,6 @@ fsp_parser_get_request_token (FspParser *self,
if (g_str_has_prefix (response_array[i], "oauth_token_secret="))
auth_token->token_secret = g_strdup (&response_array[i][19]);
}
- g_strfreev (response_array);
/* Create the GError if needed*/
if (!auth_token->token || !auth_token->token_secret)
@@ -1291,8 +1288,8 @@ fsp_parser_get_access_token (FspParser *self,
GError **error)
{
FspDataAuthToken *auth_token = NULL;
- gchar *response_str = NULL;
- gchar **response_array = NULL;
+ g_autofree gchar *response_str = NULL;
+ g_auto(GStrv) response_array = NULL;
gint i = 0;
g_return_val_if_fail (FSP_IS_PARSER (self), NULL);
@@ -1302,7 +1299,6 @@ fsp_parser_get_access_token (FspParser *self,
auth_token = FSP_DATA_AUTH_TOKEN (fsp_data_new (FSP_AUTH_TOKEN));
response_str = g_strndup (buffer, buf_size);
response_array = g_strsplit (response_str, "&", -1);
- g_free (response_str);
for (i = 0; response_array[i]; i++)
{
@@ -1321,7 +1317,6 @@ fsp_parser_get_access_token (FspParser *self,
if (g_str_has_prefix (response_array[i], "oauth_token_secret="))
auth_token->token_secret = g_strdup (&response_array[i][19]);
}
- g_strfreev (response_array);
/* Create the GError if needed*/
if (!auth_token->token || !auth_token->token_secret)
diff --git a/src/flicksoup/fsp-session.c b/src/flicksoup/fsp-session.c
index fbe9b86..a481bac 100644
--- a/src/flicksoup/fsp-session.c
+++ b/src/flicksoup/fsp-session.c
@@ -705,14 +705,14 @@ _get_soup_message_for_upload (GFile *file,
gsize length,
GHashTable *table)
{
- GFileInfo *file_info = NULL;
+ g_autoptr(GFileInfo) file_info = NULL;
SoupMessage *msg = NULL;
SoupMultipart *mpart = NULL;
SoupBuffer *buffer = NULL;
GHashTableIter iter;
const gchar *key, *value;
- gchar *mime_type = NULL;
- gchar *fileuri = NULL;
+ g_autofree gchar *mime_type = NULL;
+ g_autofree gchar *fileuri = NULL;
gchar *auth_header = NULL;
/* Gather needed information */
@@ -724,7 +724,6 @@ _get_soup_message_for_upload (GFile *file,
NULL);
/* Check mimetype */
mime_type = g_strdup (g_file_info_get_content_type (file_info));
- g_object_unref (G_OBJECT (file_info));
/* Init multipart container */
mpart = soup_multipart_new (SOUP_FORM_MIME_TYPE_MULTIPART);
@@ -767,8 +766,6 @@ _get_soup_message_for_upload (GFile *file,
/* Free */
soup_multipart_free (mpart);
soup_buffer_free (buffer);
- g_free (fileuri);
- g_free (mime_type);
/* Return message */
return msg;
@@ -782,9 +779,9 @@ _load_file_contents_cb (GObject *object,
UploadPhotoData *up_clos = NULL;
AsyncRequestData *ard_clos = NULL;
GHashTable *extra_params = NULL;
- GFile *file = NULL;
+ g_autoptr(GFile) file = NULL;
GError *error = NULL;
- gchar *contents = NULL;
+ g_autofree gchar *contents = NULL;
gsize length;
g_return_if_fail (G_IS_FILE (object));
@@ -833,18 +830,18 @@ _load_file_contents_cb (GObject *object,
/* Free */
g_hash_table_unref (extra_params);
- g_object_unref (file);
}
else
{
/* If an error happened here, report through the async callback */
- g_warning ("Unable to get contents for file\n");
if (error)
- g_error_free (error);
+ {
+ g_warning ("Unable to get contents for file: %s", error->message);
+ g_error_free (error);
+ }
error = g_error_new (FSP_ERROR, FSP_ERROR_OTHER, "Error reading file for upload");
_build_async_result_and_complete (ard_clos, NULL, error);
}
- g_free (contents);
}
static void
@@ -885,7 +882,7 @@ static gchar *
_hmac_sha1_signature (const gchar *message,
const gchar *signing_key)
{
- gchar *signature = NULL;
+ g_autofree gchar *signature = NULL;
gchar *encoded_signature = NULL;
gcry_md_hd_t digest_obj;
unsigned char *hmac_digest;
@@ -905,7 +902,6 @@ _hmac_sha1_signature (const gchar *message,
gcry_md_close (digest_obj);
encoded_signature = _encode_uri (signature);
- g_free(signature);
return encoded_signature;
}
@@ -958,7 +954,7 @@ _get_signed_query_with_params (const gchar *api_sig,
keys = g_hash_table_get_keys (params_table);
if (keys != NULL)
{
- gchar **url_params_array = NULL;
+ g_auto(GStrv) url_params_array = NULL;
GList *k = NULL;
gint i = 0;
@@ -970,13 +966,12 @@ _get_signed_query_with_params (const gchar *api_sig,
for (k = keys; k; k = g_list_next (k))
{
gchar *key = NULL;
- gchar *actual_value = NULL;
+ g_autofree gchar *actual_value = NULL;
key = (gchar*) k->data;
actual_value = g_strdup (g_hash_table_lookup (params_table, key));
url_params_array[i++] = g_strdup_printf ("%s=%s", key, actual_value);
- g_free (actual_value);
}
/* Add those to the params array (space previously reserved) */
@@ -987,9 +982,6 @@ _get_signed_query_with_params (const gchar *api_sig,
/* Build the signed query */
retval = g_strjoinv ("&", url_params_array);
-
- /* Free */
- g_strfreev (url_params_array);
}
g_list_free (keys);
g_hash_table_unref (params_table);
@@ -1023,7 +1015,7 @@ _check_errors_on_soup_response (SoupMessage *msg,
GError **error)
{
GError *err = NULL;
- gchar *response_str = NULL;
+ g_autofree gchar *response_str = NULL;
g_assert (SOUP_IS_MESSAGE (msg));
@@ -1058,8 +1050,6 @@ _check_errors_on_soup_response (SoupMessage *msg,
"Network error");
}
- g_free (response_str);
-
/* Propagate error */
if (err != NULL)
g_propagate_error (error, err);
@@ -1093,9 +1083,8 @@ _get_params_str_for_signature (GHashTable *params_table,
const gchar *signing_key,
AuthorizationMethod auth_method)
{
- GList *keys = NULL;
- gchar **params_str_array = NULL;
- gchar *params_str = NULL;
+ g_autoptr(GList) keys = NULL;
+ g_auto(GStrv) params_str_array = NULL;
GList *k = NULL;
gboolean old_auth_method = FALSE;
gint i = 0;
@@ -1134,12 +1123,7 @@ _get_params_str_for_signature (GHashTable *params_table,
}
params_str_array[i] = NULL;
- params_str = g_strjoinv (old_auth_method ? NULL : "&", params_str_array);
- g_strfreev (params_str_array);
-
- g_list_free (keys);
-
- return params_str;
+ return g_strjoinv (old_auth_method ? NULL : "&", params_str_array);
}
static gchar *
@@ -1149,10 +1133,9 @@ _calculate_api_signature (const gchar *url,
const gchar *http_method,
AuthorizationMethod auth_method)
{
- gchar *base_string = NULL;
- gchar *encoded_params = NULL;
- gchar *encoded_url = NULL;
- gchar *api_sig = NULL;
+ g_autofree gchar *base_string = NULL;
+ g_autofree gchar *encoded_params = NULL;
+ g_autofree gchar *encoded_url = NULL;
if (!params_str)
return NULL;
@@ -1165,13 +1148,8 @@ _calculate_api_signature (const gchar *url,
encoded_params = _encode_uri (params_str);
base_string = g_strdup_printf ("%s&%s&%s", http_method, encoded_url, encoded_params);
DEBUG ("Base string for signing: %s", base_string);
- g_free (encoded_url);
- g_free (encoded_params);
- api_sig = _hmac_sha1_signature (base_string, signing_key);
- g_free (base_string);
-
- return api_sig;
+ return _hmac_sha1_signature (base_string, signing_key);
}
static gchar *
@@ -1181,17 +1159,13 @@ _get_api_signature_from_hash_table (const gchar *url,
const gchar *http_method,
AuthorizationMethod auth_method)
{
- gchar *api_sig = NULL;
- gchar *params_str = NULL;
+ g_autofree gchar *params_str = NULL;
g_return_val_if_fail (params_table != NULL, NULL);
/* Get the signature string and calculate the api_sig value */
params_str = _get_params_str_for_signature (params_table, signing_key, auth_method);
- api_sig = _calculate_api_signature (url, params_str, signing_key, http_method, auth_method);
- g_free (params_str);
-
- return api_sig;
+ return _calculate_api_signature (url, params_str, signing_key, http_method, auth_method);
}
static void
@@ -1199,15 +1173,14 @@ _fill_hash_table_with_oauth_params (GHashTable *table,
const gchar *api_key,
const gchar *token)
{
+ g_autofree gchar *random_str = NULL;
gchar *timestamp = NULL;
- gchar *random_str = NULL;
gchar *nonce = NULL;
/* Add mandatory parameters to the hash table */
timestamp = g_strdup_printf ("%d", (gint) time(NULL));
random_str = g_strdup_printf ("%d_%s", g_random_int (), timestamp);
nonce = g_compute_checksum_for_string (G_CHECKSUM_MD5, random_str, -1);
- g_free (random_str);
g_hash_table_insert (table, g_strdup ("oauth_timestamp"), timestamp);
g_hash_table_insert (table, g_strdup ("oauth_nonce"), nonce);
@@ -1230,9 +1203,9 @@ _get_signed_url (FspSession *self,
{
va_list args;
GHashTable *table = NULL;
- gchar *signing_key = NULL;
- gchar *signed_query = NULL;
- gchar *api_sig = NULL;
+ g_autofree gchar *signing_key = NULL;
+ g_autofree gchar *signed_query = NULL;
+ g_autofree gchar *api_sig = NULL;
gchar *retval = NULL;
const gchar *token = NULL;
const gchar *token_secret = NULL;
@@ -1272,19 +1245,16 @@ _get_signed_url (FspSession *self,
}
api_sig = _get_api_signature_from_hash_table (url, table, signing_key, "GET", auth_method);
- g_free (signing_key);
/* Get the signed URL with the needed params */
if ((table != NULL) && (api_sig != NULL))
signed_query = _get_signed_query_with_params (api_sig, table, auth_method);
g_hash_table_unref (table);
- g_free (api_sig);
va_end (args);
retval = g_strdup_printf ("%s?%s", url, signed_query);
- g_free (signed_query);
return retval;
}
@@ -1388,7 +1358,7 @@ _handle_soup_response (SoupMessage *msg,
AsyncRequestData *clos = NULL;
gpointer result = NULL;
GError *err = NULL;
- gchar *response_str = NULL;
+ g_autofree gchar *response_str = NULL;
gulong response_len = 0;
g_assert (SOUP_IS_MESSAGE (msg));
@@ -1412,8 +1382,6 @@ _handle_soup_response (SoupMessage *msg,
/* Build response and call async callback */
_build_async_result_and_complete (clos, result, err);
-
- g_free (response_str);
}
static void
@@ -1421,7 +1389,7 @@ _build_async_result_and_complete (AsyncRequestData *clos,
gpointer result,
GError *error)
{
- GTask *task = NULL;
+ g_autoptr(GTask) task = NULL;
GObject *object = NULL;
GCancellableData *cancellable_data = NULL;
GCancellable *cancellable = NULL;
@@ -1458,8 +1426,6 @@ _build_async_result_and_complete (AsyncRequestData *clos,
g_task_return_error (task, error);
else
g_task_return_pointer (task, result, NULL);
-
- g_object_unref (G_OBJECT (task));
}
static gpointer
@@ -1818,7 +1784,7 @@ fsp_session_get_auth_url (FspSession *self,
GAsyncReadyCallback cb,
gpointer data)
{
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
@@ -1837,8 +1803,6 @@ fsp_session_get_auth_url (FspSession *self,
_perform_async_request (self->soup_session, url,
_get_request_token_session_cb, G_OBJECT (self),
c, cb, fsp_session_get_auth_url, data);
-
- g_free (url);
}
gchar *
@@ -1888,7 +1852,7 @@ fsp_session_complete_auth (FspSession *self,
if (self->tmp_token != NULL && self->tmp_token_secret != NULL)
{
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
/* Build the signed url */
url = _get_signed_url (self,
@@ -1902,8 +1866,6 @@ fsp_session_complete_auth (FspSession *self,
_perform_async_request (self->soup_session, url,
_get_access_token_soup_session_cb, G_OBJECT (self),
c, cb, fsp_session_complete_auth, data);
-
- g_free (url);
}
else
{
@@ -1954,7 +1916,7 @@ fsp_session_exchange_token (FspSession *self,
if (self->token != NULL)
{
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
/* Build the signed url */
url = _get_signed_url (self,
@@ -1968,8 +1930,6 @@ fsp_session_exchange_token (FspSession *self,
_perform_async_request (self->soup_session, url,
_exchange_token_soup_session_cb, G_OBJECT (self),
c, cb, fsp_session_exchange_token, data);
-
- g_free (url);
}
else
{
@@ -2014,7 +1974,7 @@ fsp_session_check_auth_info (FspSession *self,
if (self->token != NULL)
{
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
/* Build the signed url */
url = _get_signed_url (self,
@@ -2028,8 +1988,6 @@ fsp_session_check_auth_info (FspSession *self,
_perform_async_request (self->soup_session, url,
_check_token_soup_session_cb, G_OBJECT (self),
c, cb, fsp_session_check_auth_info, data);
-
- g_free (url);
}
else
{
@@ -2069,7 +2027,7 @@ fsp_session_get_upload_status (FspSession *self,
if (self->token != NULL)
{
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
/* Build the signed url */
url = _get_signed_url (self,
@@ -2083,8 +2041,6 @@ fsp_session_get_upload_status (FspSession *self,
_perform_async_request (self->soup_session, url,
_get_upload_status_soup_session_cb, G_OBJECT (self),
c, cb, fsp_session_get_upload_status, data);
-
- g_free (url);
}
else
{
@@ -2134,7 +2090,7 @@ fsp_session_upload (FspSession *self,
AsyncRequestData *ard_clos = NULL;
UploadPhotoData *up_clos = NULL;
GFile *file = NULL;
- gchar *signing_key = NULL;
+ g_autofree gchar *signing_key = NULL;
gchar *api_sig = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
@@ -2168,7 +2124,6 @@ fsp_session_upload (FspSession *self,
_decode_param_from_table_for_signature (extra_params, "tags");
g_hash_table_insert (extra_params, g_strdup ("oauth_signature"), api_sig);
- g_free (signing_key);
/* Save important data for the callback */
ard_clos = g_slice_new0 (AsyncRequestData);
@@ -2211,7 +2166,7 @@ fsp_session_get_info (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
g_return_if_fail (photo_id != NULL);
@@ -2230,8 +2185,6 @@ fsp_session_get_info (FspSession *self,
_perform_async_request (soup_session, url,
_photo_get_info_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_get_info, data);
-
- g_free (url);
}
FspDataPhotoInfo *
@@ -2258,7 +2211,7 @@ fsp_session_get_photosets (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
@@ -2275,8 +2228,6 @@ fsp_session_get_photosets (FspSession *self,
_perform_async_request (soup_session, url,
_get_photosets_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_get_photosets, data);
-
- g_free (url);
}
GSList *
@@ -2301,7 +2252,7 @@ fsp_session_add_to_photoset (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
g_return_if_fail (photo_id != NULL);
@@ -2322,8 +2273,6 @@ fsp_session_add_to_photoset (FspSession *self,
_perform_async_request (soup_session, url,
_add_to_photoset_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_add_to_photoset, data);
-
- g_free (url);
}
gboolean
@@ -2352,7 +2301,7 @@ fsp_session_create_photoset (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
g_return_if_fail (title != NULL);
@@ -2374,8 +2323,6 @@ fsp_session_create_photoset (FspSession *self,
_perform_async_request (soup_session, url,
_create_photoset_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_create_photoset, data);
-
- g_free (url);
}
gchar *
@@ -2402,7 +2349,7 @@ fsp_session_get_groups (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
@@ -2419,8 +2366,6 @@ fsp_session_get_groups (FspSession *self,
_perform_async_request (soup_session, url,
_get_groups_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_get_groups, data);
-
- g_free (url);
}
GSList *
@@ -2445,7 +2390,7 @@ fsp_session_add_to_group (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
g_return_if_fail (photo_id != NULL);
@@ -2466,8 +2411,6 @@ fsp_session_add_to_group (FspSession *self,
_perform_async_request (soup_session, url,
_add_to_group_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_add_to_group, data);
-
- g_free (url);
}
gboolean
@@ -2493,7 +2436,7 @@ fsp_session_get_tags_list (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
@@ -2510,8 +2453,6 @@ fsp_session_get_tags_list (FspSession *self,
_perform_async_request (soup_session, url,
_get_tags_list_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_get_tags_list, data);
-
- g_free (url);
}
GSList *
@@ -2535,8 +2476,8 @@ fsp_session_set_license (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar *license_str = NULL;
- gchar *url = NULL;
+ g_autofree gchar *license_str = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
g_return_if_fail (photo_id != NULL);
@@ -2551,15 +2492,12 @@ fsp_session_set_license (FspSession *self,
"photo_id", photo_id,
"license_id", license_str,
NULL);
- g_free (license_str);
/* Perform the async request */
soup_session = _get_soup_session (self);
_perform_async_request (soup_session, url,
_set_license_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_set_license, data);
-
- g_free (url);
}
gboolean
@@ -2589,9 +2527,9 @@ fsp_session_set_location (FspSession *self,
SoupSession *soup_session = NULL;
gchar lat_str[G_ASCII_DTOSTR_BUF_SIZE];
gchar lon_str[G_ASCII_DTOSTR_BUF_SIZE];
- gchar *accuracy_str = NULL;
- gchar *context_str = NULL;
- gchar *url = NULL;
+ g_autofree gchar *accuracy_str = NULL;
+ g_autofree gchar *context_str = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
g_return_if_fail (photo_id != NULL);
@@ -2617,16 +2555,12 @@ fsp_session_set_location (FspSession *self,
"accuracy", accuracy_str,
"context", context_str,
NULL);
- g_free (accuracy_str);
- g_free (context_str);
/* Perform the async request */
soup_session = _get_soup_session (self);
_perform_async_request (soup_session, url,
_set_location_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_set_location, data);
-
- g_free (url);
}
gboolean
@@ -2653,7 +2587,7 @@ fsp_session_get_location (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar *url = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
g_return_if_fail (photo_id != NULL);
@@ -2671,8 +2605,6 @@ fsp_session_get_location (FspSession *self,
_perform_async_request (soup_session, url,
_get_location_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_get_location, data);
-
- g_free (url);
}
FspDataLocation *
@@ -2701,8 +2633,8 @@ fsp_session_set_date_posted (FspSession *self,
gpointer data)
{
SoupSession *soup_session = NULL;
- gchar* date_str;
- gchar *url = NULL;
+ g_autofree gchar* date_str = NULL;
+ g_autofree gchar *url = NULL;
g_return_if_fail (FSP_IS_SESSION (self));
g_return_if_fail (photo_id != NULL);
@@ -2726,9 +2658,6 @@ fsp_session_set_date_posted (FspSession *self,
_perform_async_request (soup_session, url,
_set_dates_soup_session_cb, G_OBJECT (self),
cancellable, callback, fsp_session_set_date_posted, data);
-
- g_free (date_str);
- g_free (url);
}
gboolean
diff --git a/src/frogr-about-dialog.c b/src/frogr-about-dialog.c
index 08ceb3e..c4bc157 100644
--- a/src/frogr-about-dialog.c
+++ b/src/frogr-about-dialog.c
@@ -47,15 +47,13 @@ static const gchar *website = "http://wiki.gnome.org/Apps/Frogr";
void
frogr_about_dialog_show (GtkWindow *parent)
{
- GdkPixbuf *logo = NULL;
- gchar *version = NULL;
- gchar *icon_full_path = NULL;
+ g_autoptr(GdkPixbuf) logo = NULL;
+ g_autofree gchar *version = NULL;
+ g_autofree gchar *icon_full_path = NULL;
icon_full_path = g_strdup_printf ("%s/" ABOUT_DIALOG_ICON,
frogr_util_get_icons_dir ());
logo = gdk_pixbuf_new_from_file (icon_full_path, NULL);
- g_free (icon_full_path);
-
version = g_strdup_printf ("%s~unreleased", PACKAGE_VERSION);
/* Show about dialog */
@@ -72,7 +70,4 @@ frogr_about_dialog_show (GtkWindow *parent)
"translator-credits", _("translator-credits"),
"modal", TRUE,
NULL);
-
- g_object_unref (logo);
- g_free (version);
}
diff --git a/src/frogr-add-tags-dialog.c b/src/frogr-add-tags-dialog.c
index bd5f15a..1e95427 100644
--- a/src/frogr-add-tags-dialog.c
+++ b/src/frogr-add-tags-dialog.c
@@ -70,7 +70,7 @@ _dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
if (response == GTK_RESPONSE_ACCEPT)
{
FrogrAddTagsDialog *self = NULL;
- gchar *tags = NULL;
+ g_autofree gchar *tags = NULL;
self = FROGR_ADD_TAGS_DIALOG (dialog);
@@ -98,9 +98,6 @@ _dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
model = frogr_controller_get_model (frogr_controller_get_instance ());
frogr_model_add_local_tags_from_string (model, tags);
}
-
- /* Free */
- g_free (tags);
}
/* Destroy the dialog */
@@ -150,8 +147,7 @@ _frogr_add_tags_dialog_dispose (GObject *object)
if (dialog->pictures)
{
- g_slist_foreach (dialog->pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (dialog->pictures);
+ g_slist_free_full (dialog->pictures, g_object_unref);
dialog->pictures = NULL;
}
diff --git a/src/frogr-add-to-group-dialog.c b/src/frogr-add-to-group-dialog.c
index 5258f4c..07a219b 100644
--- a/src/frogr-add-to-group-dialog.c
+++ b/src/frogr-add-to-group-dialog.c
@@ -225,8 +225,8 @@ _tree_iter_compare_n_elements_func (GtkTreeModel *model,
GtkTreeIter *b,
gpointer data)
{
- gchar *a_str = NULL;
- gchar *b_str = NULL;
+ g_autofree gchar *a_str = NULL;
+ g_autofree gchar *b_str = NULL;
gint a_value = 0;
gint b_value = 0;
@@ -238,9 +238,6 @@ _tree_iter_compare_n_elements_func (GtkTreeModel *model,
a_value = g_ascii_strtoll (a_str, NULL, 10);
b_value = g_ascii_strtoll (b_str, NULL, 10);
- g_free (a_str);
- g_free (b_str);
-
return (a_value - b_value);
}
@@ -289,7 +286,7 @@ _fill_dialog_with_data (FrogrAddToGroupDialog *self)
gtk_tree_model_get_iter_first (self->treemodel, &iter);
do
{
- FrogrGroup *group = NULL;
+ g_autoptr(FrogrGroup) group = NULL;
GSList *p_item = NULL;
gboolean do_check = TRUE;
@@ -307,7 +304,6 @@ _fill_dialog_with_data (FrogrAddToGroupDialog *self)
break;
}
}
- g_object_unref (group);
gtk_list_store_set (GTK_LIST_STORE (self->treemodel), &iter,
CHECKBOX_COL, do_check, -1);
@@ -463,15 +459,13 @@ _frogr_add_to_group_dialog_dispose (GObject *object)
if (dialog->pictures)
{
- g_slist_foreach (dialog->pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (dialog->pictures);
+ g_slist_free_full (dialog->pictures, g_object_unref);
dialog->pictures = NULL;
}
if (dialog->groups)
{
- g_slist_foreach (dialog->groups, (GFunc)g_object_unref, NULL);
- g_slist_free (dialog->groups);
+ g_slist_free_full (dialog->groups, g_object_unref);
dialog->groups = NULL;
}
diff --git a/src/frogr-add-to-set-dialog.c b/src/frogr-add-to-set-dialog.c
index b7f37a8..4fbd208 100644
--- a/src/frogr-add-to-set-dialog.c
+++ b/src/frogr-add-to-set-dialog.c
@@ -226,8 +226,8 @@ _tree_iter_compare_n_elements_func (GtkTreeModel *model,
GtkTreeIter *b,
gpointer data)
{
- gchar *a_str = NULL;
- gchar *b_str = NULL;
+ g_autofree gchar *a_str = NULL;
+ g_autofree gchar *b_str = NULL;
gint a_value = 0;
gint b_value = 0;
@@ -239,9 +239,6 @@ _tree_iter_compare_n_elements_func (GtkTreeModel *model,
a_value = g_ascii_strtoll (a_str, NULL, 10);
b_value = g_ascii_strtoll (b_str, NULL, 10);
- g_free (a_str);
- g_free (b_str);
-
return (a_value - b_value);
}
@@ -290,7 +287,7 @@ _fill_dialog_with_data (FrogrAddToSetDialog *self)
gtk_tree_model_get_iter_first (self->treemodel, &iter);
do
{
- FrogrPhotoSet *set = NULL;
+ g_autoptr(FrogrPhotoSet) set = NULL;
GSList *p_item = NULL;
gboolean do_check = TRUE;
@@ -308,7 +305,6 @@ _fill_dialog_with_data (FrogrAddToSetDialog *self)
break;
}
}
- g_object_unref (set);
gtk_list_store_set (GTK_LIST_STORE (self->treemodel), &iter,
CHECKBOX_COL, do_check, -1);
@@ -464,15 +460,13 @@ _frogr_add_to_set_dialog_dispose (GObject *object)
if (dialog->pictures)
{
- g_slist_foreach (dialog->pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (dialog->pictures);
+ g_slist_free_full (dialog->pictures, g_object_unref);
dialog->pictures = NULL;
}
if (dialog->photosets)
{
- g_slist_foreach (dialog->photosets, (GFunc)g_object_unref, NULL);
- g_slist_free (dialog->photosets);
+ g_slist_free_full (dialog->photosets, g_object_unref);
dialog->photosets = NULL;
}
diff --git a/src/frogr-auth-dialog.c b/src/frogr-auth-dialog.c
index b844dbf..9935689 100644
--- a/src/frogr-auth-dialog.c
+++ b/src/frogr-auth-dialog.c
@@ -50,7 +50,7 @@ static void
_ask_for_authorization (GtkWindow *parent)
{
GtkWidget *dialog = NULL;
- gchar *title = NULL;
+ g_autofree gchar *title = NULL;
dialog = gtk_message_dialog_new (parent,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -62,7 +62,6 @@ _ask_for_authorization (GtkWindow *parent)
title = g_strdup_printf (_("Authorize %s"), APP_SHORTNAME);
gtk_window_set_title (GTK_WINDOW (dialog), title);
- g_free (title);
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (_ask_for_authorization_response_cb), NULL);
@@ -144,7 +143,7 @@ _ask_for_auth_confirmation (GtkWindow *parent)
GtkWidget *vbox = NULL;
GtkWidget *ver_code_entry = NULL;
GtkWidget *label = NULL;
- gchar *title = NULL;
+ g_autofree gchar *title = NULL;
title = g_strdup_printf (_("Authorize %s"), APP_SHORTNAME);
dialog = gtk_dialog_new_with_buttons (title,
@@ -156,7 +155,6 @@ _ask_for_auth_confirmation (GtkWindow *parent)
GTK_RESPONSE_CLOSE,
NULL);
gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
- g_free (title);
/* Fill action area */
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
@@ -203,7 +201,7 @@ _ask_for_auth_confirmation_response_cb (GtkDialog *dialog, gint response, gpoint
const gchar *vercode_part1 = NULL;
const gchar *vercode_part2 = NULL;
const gchar *vercode_part3 = NULL;
- gchar *vercode_full = NULL;
+ g_autofree gchar *vercode_full = NULL;
vercode_part1 = _get_entry_code_for_dialog (dialog, "vercode-1");
vercode_part2 = _get_entry_code_for_dialog (dialog, "vercode-2");
@@ -219,8 +217,6 @@ _ask_for_auth_confirmation_response_cb (GtkDialog *dialog, gint response, gpoint
}
else
frogr_util_show_error_dialog (GTK_WINDOW (dialog), _("Invalid verification code"));
-
- g_free (vercode_full);
}
if (response == GTK_RESPONSE_CANCEL || valid)
diff --git a/src/frogr-config.c b/src/frogr-config.c
index dee445a..2de0fa2 100644
--- a/src/frogr-config.c
+++ b/src/frogr-config.c
@@ -145,7 +145,7 @@ _find_account_by_username (FrogrConfig *self, const gchar *username)
static void
_load_settings (FrogrConfig *self)
{
- gchar *xml_path = NULL;
+ g_autofree gchar *xml_path = NULL;
xmlNodePtr node = NULL;
xmlDocPtr xml = NULL;
@@ -313,8 +313,6 @@ _load_settings (FrogrConfig *self)
if (xml)
xmlFreeDoc (xml);
-
- g_free (xml_path);
}
static void
@@ -499,7 +497,7 @@ _load_proxy_data_xml (FrogrConfig *self,
static void
_load_accounts (FrogrConfig *self)
{
- gchar *xml_path = NULL;
+ g_autofree gchar *xml_path = NULL;
xmlNodePtr node = NULL;
xmlDocPtr xml = NULL;
@@ -522,7 +520,7 @@ _load_accounts (FrogrConfig *self)
/* Node "account" found, stop searching */
if (!xmlStrcmp (node->name, (const xmlChar*) "account"))
{
- FrogrAccount *account = frogr_account_new ();
+ g_autoptr(FrogrAccount) account = frogr_account_new ();
if (_load_account_xml (account, xml, node))
frogr_config_add_account (self, account);
@@ -536,8 +534,6 @@ _load_accounts (FrogrConfig *self)
xmlSaveFormatFileEnc (xml_path, xml, "UTF-8", 1);
}
-
- g_object_unref (account);
}
}
}
@@ -553,8 +549,6 @@ _load_accounts (FrogrConfig *self)
if (xml)
xmlFreeDoc (xml);
-
- g_free (xml_path);
}
static gboolean
@@ -652,7 +646,7 @@ _save_settings (FrogrConfig *self)
xmlDocPtr xml = NULL;
xmlNodePtr root = NULL;
xmlNodePtr node = NULL;
- gchar *xml_path = NULL;
+ g_autofree gchar *xml_path = NULL;
gboolean retval = TRUE;
g_return_val_if_fail (FROGR_IS_CONFIG (self), FALSE);
@@ -714,7 +708,6 @@ _save_settings (FrogrConfig *self)
/* Free */
xmlFreeDoc (xml);
- g_free (xml_path);
return retval;
}
@@ -726,7 +719,7 @@ _save_accounts (FrogrConfig *self)
GSList *item = NULL;
xmlDocPtr xml = NULL;
xmlNodePtr root = NULL;
- gchar *xml_path = NULL;
+ g_autofree gchar *xml_path = NULL;
gboolean retval = TRUE;
g_return_val_if_fail (FROGR_IS_CONFIG (self), FALSE);
@@ -751,7 +744,6 @@ _save_accounts (FrogrConfig *self)
/* Free */
xmlFreeDoc (xml);
- g_free (xml_path);
return retval;
}
@@ -788,11 +780,10 @@ static xmlNodePtr
_xml_add_int_child (xmlNodePtr parent, const gchar *xml_name, gint value)
{
xmlNodePtr result = NULL;
- gchar *int_str = NULL;
+ g_autofree gchar *int_str = NULL;
int_str = g_strdup_printf ("%d", value);
result = _xml_add_string_child (parent, xml_name, int_str);
- g_free (int_str);
return result;
}
@@ -801,11 +792,10 @@ static xmlNodePtr
_xml_add_bool_child (xmlNodePtr parent, const gchar *xml_name, gboolean value)
{
xmlNodePtr result = NULL;
- gchar *bool_str = NULL;
+ g_autofree gchar *bool_str = NULL;
bool_str = g_strdup_printf ("%d", value ? 1 : 0);
result = _xml_add_string_child (parent, xml_name, bool_str);
- g_free (bool_str);
return result;
}
@@ -817,7 +807,7 @@ _xml_add_string_child (xmlNodePtr parent,
{
xmlNodePtr node = NULL;
xmlChar *enc = NULL;
- gchar *actual_content = NULL;
+ g_autofree gchar *actual_content = NULL;
g_return_val_if_fail (parent != NULL, NULL);
g_return_val_if_fail (xml_name != NULL, NULL);
@@ -832,7 +822,6 @@ _xml_add_string_child (xmlNodePtr parent,
xmlNodeSetContent (node, enc);
xmlFree (enc);
- g_free (actual_content);
xmlAddChild (parent, node);
@@ -875,8 +864,7 @@ _dispose (GObject *object)
if (config->accounts)
{
- g_slist_foreach (config->accounts, (GFunc)g_object_unref, NULL);
- g_slist_free (config->accounts);
+ g_slist_free_full (config->accounts, g_object_unref);
config->accounts = NULL;
}
@@ -934,7 +922,7 @@ frogr_config_class_init (FrogrConfigClass *klass)
static void
frogr_config_init (FrogrConfig *self)
{
- gchar *config_dir = NULL;
+ g_autofree gchar *config_dir = NULL;
self->config_dir = NULL;
self->active_account = NULL;
@@ -992,8 +980,6 @@ frogr_config_init (FrogrConfig *self)
g_warning ("Could not create config directory '%s' (%s)",
config_dir, strerror (errno));
}
-
- g_free (config_dir);
}
FrogrConfig*
@@ -1080,7 +1066,7 @@ frogr_config_get_active_account (FrogrConfig *self)
gboolean
frogr_config_remove_account (FrogrConfig *self, const gchar *username)
{
- FrogrAccount *found_account = NULL;
+ g_autoptr(FrogrAccount) found_account = NULL;
g_return_val_if_fail (FROGR_IS_CONFIG (self), FALSE);
g_return_val_if_fail (username != NULL, FALSE);
@@ -1090,8 +1076,6 @@ frogr_config_remove_account (FrogrConfig *self, const gchar *username)
if (found_account)
{
self->accounts = g_slist_remove (self->accounts, found_account);
- g_object_unref (found_account);
-
return TRUE;
}
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index 0292288..60d61a4 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -314,7 +314,7 @@ static gboolean
_load_project_file_on_idle (gpointer data)
{
FrogrController *fcontroller = NULL;
- gchar *filepath = NULL;
+ g_autofree gchar *filepath = NULL;
g_return_val_if_fail (data, FALSE);
@@ -322,7 +322,6 @@ _load_project_file_on_idle (gpointer data)
filepath = (gchar *)data;
frogr_controller_open_project_from_file (fcontroller, filepath);
- g_free (filepath);
return G_SOURCE_REMOVE;
}
@@ -386,7 +385,7 @@ static void
_g_application_open_files_cb (GApplication *app, GFile **files, gint n_files, gchar *hint, gpointer data)
{
FrogrController *self = FROGR_CONTROLLER (data);
- GFileInfo *file_info = NULL;
+ g_autoptr(GFileInfo) file_info = NULL;
gboolean is_project_file = FALSE;
DEBUG ("Trying to open %d files\n", n_files);
@@ -408,7 +407,6 @@ _g_application_open_files_cb (GApplication *app, GFile **files, gint n_files, gc
normally with MIME types 'image' and 'video' */
mime_type = g_file_info_get_content_type (file_info);
is_project_file = g_str_has_prefix (mime_type, "text");
- g_object_unref (file_info);
}
if (is_project_file)
@@ -566,8 +564,8 @@ static void
_handle_flicksoup_error (FrogrController *self, GError *error, gboolean notify_user)
{
void (* error_function) (GtkWindow *, const gchar *) = NULL;
- gchar *msg = NULL;
- gchar *video_quota_msg = NULL;
+ g_autofree gchar *msg = NULL;
+ g_autofree gchar *video_quota_msg = NULL;
gint n_videos = 0;
error_function = frogr_util_show_error_dialog;
@@ -606,7 +604,6 @@ _handle_flicksoup_error (FrogrController *self, GError *error, gboolean notify_u
msg = g_strdup_printf ("%s\n%s",
_("Error uploading video:\nYou can't upload more videos with this account"),
video_quota_msg);
- g_free (video_quota_msg);
break;
case FSP_ERROR_PHOTO_NOT_FOUND:
@@ -678,7 +675,6 @@ _handle_flicksoup_error (FrogrController *self, GError *error, gboolean notify_u
error_function (GTK_WINDOW (self->mainview), msg);
DEBUG ("%s", msg);
- g_free (msg);
}
static void
@@ -733,8 +729,8 @@ _get_auth_url_cb (GObject *obj, GAsyncResult *res, gpointer data)
FspSession *session = NULL;
CancellableOperationData *co_data = NULL;
FrogrController *self = NULL;
- GError *error = NULL;
- gchar *auth_url = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autofree gchar *auth_url = NULL;
session = FSP_SESSION (obj);
co_data = (CancellableOperationData*) data;
@@ -743,7 +739,7 @@ _get_auth_url_cb (GObject *obj, GAsyncResult *res, gpointer data)
auth_url = fsp_session_get_auth_url_finish (session, res, &error);
if (auth_url != NULL && error == NULL)
{
- gchar *url_with_permissions = NULL;
+ g_autofree gchar *url_with_permissions = NULL;
url_with_permissions = g_strdup_printf ("%s&perms=write", auth_url);
frogr_util_open_uri (url_with_permissions);
@@ -752,16 +748,12 @@ _get_auth_url_cb (GObject *obj, GAsyncResult *res, gpointer data)
frogr_auth_dialog_show (GTK_WINDOW (self->mainview), CONFIRM_AUTHORIZATION);
DEBUG ("Auth URL: %s", url_with_permissions);
-
- g_free (url_with_permissions);
- g_free (auth_url);
}
if (error != NULL)
{
_handle_flicksoup_error (self, error, TRUE);
DEBUG ("Error getting auth URL: %s", error->message);
- g_error_free (error);
}
frogr_main_view_hide_progress (self->mainview);
@@ -779,7 +771,7 @@ _complete_auth_cb (GObject *object, GAsyncResult *result, gpointer data)
CancellableOperationData *co_data = NULL;
FrogrController *controller = NULL;
FspDataAuthToken *auth_token = NULL;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
session = FSP_SESSION (object);
co_data = (CancellableOperationData*) data;
@@ -814,7 +806,6 @@ _complete_auth_cb (GObject *object, GAsyncResult *result, gpointer data)
{
_handle_flicksoup_error (controller, error, TRUE);
DEBUG ("Authorization failed: %s", error->message);
- g_error_free (error);
}
frogr_main_view_hide_progress (controller->mainview);
@@ -830,7 +821,7 @@ _exchange_token_cb (GObject *object, GAsyncResult *result, gpointer data)
{
FspSession *session = NULL;
FrogrController *controller = NULL;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
session = FSP_SESSION (object);
controller = FROGR_CONTROLLER (data);
@@ -859,7 +850,6 @@ _exchange_token_cb (GObject *object, GAsyncResult *result, gpointer data)
{
_handle_flicksoup_error (controller, error, TRUE);
DEBUG ("Authorization failed: %s", error->message);
- g_error_free (error);
}
frogr_main_view_hide_progress (controller->mainview);
@@ -913,13 +903,13 @@ _invalidate_extra_data (FrogrController *self)
static void
_update_upload_progress (FrogrController *self, UploadPicturesData *up_data)
{
- gchar *description = NULL;
- gchar *status_text = NULL;
+ g_autofree gchar *description = NULL;
+ g_autofree gchar *status_text = NULL;
if (up_data->current)
{
FrogrPicture *picture = FROGR_PICTURE (up_data->current->data);
- gchar *title = g_strdup (frogr_picture_get_title (picture));
+ g_autofree gchar *title = g_strdup (frogr_picture_get_title (picture));
/* Update progress */
if (up_data->upload_attempts > 0)
@@ -932,14 +922,9 @@ _update_upload_progress (FrogrController *self, UploadPicturesData *up_data)
description = g_strdup_printf (_("Uploading '%s'…"), title);
}
status_text = g_strdup_printf ("%d / %d", up_data->index, up_data->n_pictures);
- g_free (title);
}
frogr_main_view_set_progress_description(self->mainview, description);
frogr_main_view_set_progress_status_text (self->mainview, status_text);
-
- /* Free */
- g_free (description);
- g_free (status_text);
}
static void
@@ -1027,8 +1012,8 @@ _upload_picture_cb (GObject *object, GAsyncResult *res, gpointer data)
UploadPicturesData *up_data = NULL;
FrogrController *controller = NULL;
FrogrPicture *picture = NULL;
+ g_autofree gchar *photo_id = NULL;
GError *error = NULL;
- gchar *photo_id = NULL;
session = FSP_SESSION (object);
uop_data = (UploadOnePictureData*) data;
@@ -1037,10 +1022,7 @@ _upload_picture_cb (GObject *object, GAsyncResult *res, gpointer data)
photo_id = fsp_session_upload_finish (session, res, &error);
if (photo_id)
- {
- frogr_picture_set_id (picture, photo_id);
- g_free (photo_id);
- }
+ frogr_picture_set_id (picture, photo_id);
/* Stop reporting to the user */
g_signal_handlers_disconnect_by_func (controller->session, _data_fraction_sent_cb, controller);
@@ -1112,10 +1094,7 @@ _finish_upload_pictures_process (FrogrController *self, UploadPicturesData *up_d
_set_state (self, FROGR_STATE_IDLE);
if (up_data->pictures)
- {
- g_slist_foreach (up_data->pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (up_data->pictures);
- }
+ g_slist_free_full (up_data->pictures, g_object_unref);
g_slice_free (UploadPicturesData, up_data);
}
@@ -1198,7 +1177,7 @@ static void
_set_license_for_picture (FrogrController *self, UploadOnePictureData *uop_data)
{
FrogrPicture *picture = NULL;
- gchar *debug_msg = NULL;
+ g_autofree gchar *debug_msg = NULL;
self->setting_license = TRUE;
picture = uop_data->picture;
@@ -1214,7 +1193,6 @@ _set_license_for_picture (FrogrController *self, UploadOnePictureData *uop_data)
frogr_picture_get_license (picture),
frogr_picture_get_title (picture));
DEBUG ("%s", debug_msg);
- g_free (debug_msg);
}
static void
@@ -1261,7 +1239,7 @@ _set_location_for_picture (FrogrController *self, UploadOnePictureData *uop_data
FrogrPicture *picture = NULL;
FrogrLocation *location = NULL;
FspDataLocation *data_location = NULL;
- gchar *debug_msg = NULL;
+ g_autofree gchar *debug_msg = NULL;
picture = uop_data->picture;
location = frogr_picture_get_location (picture);
@@ -1284,7 +1262,6 @@ _set_location_for_picture (FrogrController *self, UploadOnePictureData *uop_data
frogr_location_get_longitude (location),
frogr_picture_get_title (picture));
DEBUG ("%s", debug_msg);
- g_free (debug_msg);
fsp_data_free (FSP_DATA (data_location));
}
@@ -1334,7 +1311,7 @@ _set_replace_date_posted_for_picture (FrogrController *self, UploadOnePictureDat
GDateTime *picture_date = NULL;
GTimeVal picture_timeval;
const gchar *picture_date_str = NULL;
- gchar *debug_msg = NULL;
+ g_autofree gchar *debug_msg = NULL;
gchar date_iso8601[20];
picture = uop_data->picture;
@@ -1379,7 +1356,6 @@ _set_replace_date_posted_for_picture (FrogrController *self, UploadOnePictureDat
debug_msg = g_strdup_printf ("Replacing 'date posted' with 'date taken' (%s) for picture %s…",
date_iso8601, frogr_picture_get_title (picture));
DEBUG ("%s", debug_msg);
- g_free (debug_msg);
g_date_time_unref (picture_date);
}
@@ -1410,7 +1386,7 @@ _create_photoset_for_picture (FrogrController *self, UploadOnePictureData *uop_d
{
FrogrPicture *picture = NULL;
FrogrPhotoSet *set = NULL;
- gchar *debug_msg = NULL;
+ g_autofree gchar *debug_msg = NULL;
picture = uop_data->picture;
set = FROGR_PHOTOSET (uop_data->photosets->data);
@@ -1430,7 +1406,6 @@ _create_photoset_for_picture (FrogrController *self, UploadOnePictureData *uop_d
frogr_photoset_get_title (set),
frogr_photoset_get_description (set));
DEBUG ("%s", debug_msg);
- g_free (debug_msg);
}
static void
@@ -1441,7 +1416,7 @@ _create_photoset_cb (GObject *object, GAsyncResult *res, gpointer data)
FrogrController *controller = NULL;
FrogrPhotoSet *set = NULL;
GSList *photosets = NULL;
- gchar *photoset_id = NULL;
+ g_autofree gchar *photoset_id = NULL;
GError *error = NULL;
session = FSP_SESSION (object);
@@ -1473,7 +1448,6 @@ _create_photoset_cb (GObject *object, GAsyncResult *res, gpointer data)
{
frogr_photoset_set_id (set, photoset_id);
frogr_photoset_set_n_photos (set, frogr_photoset_get_n_photos (set) + 1);
- g_free (photoset_id);
uop_data->after_upload_attempts[AFTER_UPLOAD_OP_ADDING_TO_SET] = 0;
uop_data->photosets = g_slist_next (photosets);
@@ -1495,7 +1469,7 @@ _add_picture_to_photoset (FrogrController *self, UploadOnePictureData *uop_data)
{
FrogrPicture *picture = NULL;
FrogrPhotoSet *set = NULL;
- gchar *debug_msg = NULL;
+ g_autofree gchar *debug_msg = NULL;
picture = uop_data->picture;
set = FROGR_PHOTOSET (uop_data->photosets->data);
@@ -1512,7 +1486,6 @@ _add_picture_to_photoset (FrogrController *self, UploadOnePictureData *uop_data)
frogr_picture_get_title (picture),
frogr_photoset_get_title (set));
DEBUG ("%s", debug_msg);
- g_free (debug_msg);
}
static void
@@ -1588,7 +1561,7 @@ _add_picture_to_group (FrogrController *self, UploadOnePictureData *uop_data)
{
FrogrPicture *picture = NULL;
FrogrGroup *group = NULL;
- gchar *debug_msg = NULL;
+ g_autofree gchar *debug_msg = NULL;
picture = uop_data->picture;
group = FROGR_GROUP (uop_data->groups->data);
@@ -1604,7 +1577,6 @@ _add_picture_to_group (FrogrController *self, UploadOnePictureData *uop_data)
frogr_picture_get_title (picture),
frogr_group_get_name (group));
DEBUG ("%s", debug_msg);
- g_free (debug_msg);
}
static void
@@ -1795,7 +1767,7 @@ _fetch_account_basic_info_cb (GObject *object, GAsyncResult *res, FetchAccountIn
FspSession *session = NULL;
FrogrController *controller = NULL;
FspDataAuthToken *auth_token = NULL;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
session = FSP_SESSION (object);
controller = frogr_controller_get_instance ();
@@ -1835,7 +1807,6 @@ _fetch_account_basic_info_cb (GObject *object, GAsyncResult *res, FetchAccountIn
{
DEBUG ("Fetching basic info from the account: %s", error->message);
_handle_flicksoup_error (controller, error, FALSE);
- g_error_free (error);
}
_fetch_account_info_finish (controller, data);
}
@@ -1864,7 +1835,7 @@ _fetch_account_upload_status_cb (GObject *object, GAsyncResult *res, FetchAccoun
FspSession *session = NULL;
FrogrController *controller = NULL;
FspDataUploadStatus *upload_status = NULL;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
session = FSP_SESSION (object);
controller = frogr_controller_get_instance ();
@@ -1910,7 +1881,6 @@ _fetch_account_upload_status_cb (GObject *object, GAsyncResult *res, FetchAccoun
{
DEBUG ("Fetching upload status for the account: %s", error->message);
_handle_flicksoup_error (controller, error, FALSE);
- g_error_free (error);
}
fsp_data_free (FSP_DATA (upload_status));
@@ -1965,9 +1935,9 @@ _fetch_photosets_cb (GObject *object, GAsyncResult *res, gpointer data)
FspSession *session = NULL;
CancellableOperationData *co_data = NULL;
FrogrController *controller = NULL;
- GSList *data_sets_list = NULL;
GSList *sets_list = NULL;
- GError *error = NULL;
+ g_autoptr(GSList) data_sets_list = NULL;
+ g_autoptr(GError) error = NULL;
gboolean valid = FALSE;
session = FSP_SESSION (object);
@@ -1984,8 +1954,6 @@ _fetch_photosets_cb (GObject *object, GAsyncResult *res, gpointer data)
/* If no photosets are found is a valid outcome */
if (error->code == FSP_ERROR_MISSING_DATA)
valid = TRUE;
-
- g_error_free (error);
}
else
{
@@ -2013,8 +1981,6 @@ _fetch_photosets_cb (GObject *object, GAsyncResult *res, gpointer data)
}
fsp_data_free (FSP_DATA (current_data_set));
}
-
- g_slist_free (data_sets_list);
}
}
@@ -2057,9 +2023,9 @@ _fetch_groups_cb (GObject *object, GAsyncResult *res, gpointer data)
FspSession *session = NULL;
CancellableOperationData *co_data = NULL;
FrogrController *controller = NULL;
- GSList *data_groups_list = NULL;
GSList *groups_list = NULL;
- GError *error = NULL;
+ g_autoptr(GSList) data_groups_list = NULL;
+ g_autoptr(GError) error = NULL;
gboolean valid = FALSE;
session = FSP_SESSION (object);
@@ -2076,8 +2042,6 @@ _fetch_groups_cb (GObject *object, GAsyncResult *res, gpointer data)
/* If no groups are found is a valid outcome */
if (error->code == FSP_ERROR_MISSING_DATA)
valid = TRUE;
-
- g_error_free (error);
}
else
{
@@ -2104,8 +2068,6 @@ _fetch_groups_cb (GObject *object, GAsyncResult *res, gpointer data)
}
fsp_data_free (FSP_DATA (data_group));
}
-
- g_slist_free (data_groups_list);
}
}
@@ -2153,7 +2115,7 @@ _fetch_tags_cb (GObject *object, GAsyncResult *res, gpointer data)
CancellableOperationData *co_data = NULL;
FrogrController *controller = NULL;
GSList *tags_list = NULL;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean valid = FALSE;
session = FSP_SESSION (object);
@@ -2172,18 +2134,13 @@ _fetch_tags_cb (GObject *object, GAsyncResult *res, gpointer data)
valid = TRUE;
tags_list = NULL;
-
- g_error_free (error);
}
else
{
/* Consider the received result valid if no previous one has arrived first */
valid = !controller->tags_fetched;
if (!valid)
- {
- g_slist_foreach (tags_list, (GFunc)g_free, NULL);
- g_slist_free (tags_list);
- }
+ g_slist_free_full (tags_list, g_free);
}
if (valid)
@@ -2206,8 +2163,7 @@ _dispose_slist_of_objects (GSList *objects)
return;
/* FrogrController's responsibility over this list ends here */
- g_slist_foreach (objects, (GFunc) g_object_unref, NULL);
- g_slist_free (objects);
+ g_slist_free_full (objects, g_object_unref);
}
static gboolean
@@ -2261,7 +2217,7 @@ _show_progress_on_idle (gpointer data)
frogr_main_view_pulse_progress (controller->mainview);
if (show_dialog)
{
- gchar *title = NULL;
+ g_autofree gchar *title = NULL;
switch (activity)
{
@@ -2282,8 +2238,6 @@ _show_progress_on_idle (gpointer data)
}
frogr_main_view_show_progress (controller->mainview, title, text);
- g_free (title);
-
return G_SOURCE_CONTINUE;
}
else
@@ -2457,8 +2411,7 @@ _frogr_controller_dispose (GObject* object)
if (controller->cancellables)
{
- g_list_foreach (controller->cancellables, (GFunc)g_object_unref, NULL);
- g_list_free (controller->cancellables);
+ g_list_free_full (controller->cancellables, g_object_unref);
controller->cancellables = NULL;
}
@@ -2547,7 +2500,7 @@ frogr_controller_get_instance (void)
gint
frogr_controller_run_app (FrogrController *self, int argc, char **argv)
{
- GtkApplication *app = NULL;
+ g_autoptr(GtkApplication) app = NULL;
gint status;
g_return_val_if_fail(FROGR_IS_CONTROLLER (self), -1);
@@ -2571,7 +2524,6 @@ frogr_controller_run_app (FrogrController *self, int argc, char **argv)
g_signal_connect (app, "open", G_CALLBACK (_g_application_open_files_cb), self);
status = g_application_run (G_APPLICATION (app), argc, argv);
- g_object_unref (app);
return status;
}
@@ -2655,7 +2607,7 @@ frogr_controller_set_proxy (FrogrController *self,
proxy_changed = fsp_session_set_custom_proxy (self->session, NULL, NULL, NULL, NULL);
DEBUG ("%s", "Not enabling the HTTP proxy");
} else {
- gchar *auth_part = NULL;
+ g_autofree gchar *auth_part = NULL;
gboolean has_username = FALSE;
gboolean has_password = FALSE;
@@ -2666,7 +2618,6 @@ frogr_controller_set_proxy (FrogrController *self,
auth_part = g_strdup_printf ("%s:%s@", username, password);
DEBUG ("Using HTTP proxy: %s%s:%s", auth_part ? auth_part : "", host, port);
- g_free (auth_part);
proxy_changed = fsp_session_set_custom_proxy (self->session,
host, port,
@@ -2965,21 +2916,19 @@ frogr_controller_upload_pictures (FrogrController *self, GSList *pictures)
/* Upload pictures */
if (!frogr_controller_is_authorized (self))
{
- gchar *msg = NULL;
+ g_autofree gchar *msg = NULL;
msg = g_strdup_printf (_("You need to properly authorize %s before"
" uploading any pictures to Flickr.\n"
"Please re-authorize it."), APP_SHORTNAME);
frogr_util_show_error_dialog (GTK_WINDOW (self->mainview), msg);
- g_free (msg);
}
else if (!frogr_controller_is_connected (self))
{
- gchar *msg = NULL;
+ g_autofree gchar *msg = NULL;
msg = g_strdup_printf (_("You need to be connected before"
" uploading any pictures to Flickr."));
frogr_util_show_error_dialog (GTK_WINDOW (self->mainview), msg);
- g_free (msg);
}
else
{
@@ -3025,8 +2974,8 @@ frogr_controller_cancel_ongoing_requests (FrogrController *self)
gboolean
frogr_controller_open_project_from_file (FrogrController *self, const gchar *path)
{
- JsonParser *json_parser = NULL;
- GError *error = NULL;
+ g_autoptr(JsonParser) json_parser = NULL;
+ g_autoptr(GError) error = NULL;
gboolean result = FALSE;
g_return_val_if_fail(FROGR_IS_CONTROLLER (self), FALSE);
@@ -3037,14 +2986,12 @@ frogr_controller_open_project_from_file (FrogrController *self, const gchar *pat
json_parser_load_from_file (json_parser, path, &error);
if (error)
{
- gchar *msg = NULL;
+ g_autofree gchar *msg = NULL;
msg = g_strdup_printf (_("Error opening project file"));
frogr_util_show_error_dialog (GTK_WINDOW (self->mainview), msg);
- g_free (msg);
DEBUG ("Error loading project file: %s", error->message);
- g_error_free (error);
}
else
{
@@ -3071,7 +3018,6 @@ frogr_controller_open_project_from_file (FrogrController *self, const gchar *pat
frogr_model_deserialize (model, data_object);
result = TRUE;
}
- g_object_unref (json_parser);
return result;
}
@@ -3080,15 +3026,15 @@ gboolean
frogr_controller_save_project_to_file (FrogrController *self, const gchar *path)
{
FrogrModel *model = NULL;
- JsonGenerator *json_gen = NULL;
- JsonNode *root_node = NULL;
- JsonObject *root_object = NULL;
+ g_autoptr(JsonGenerator) json_gen = NULL;
+ g_autoptr(JsonNode) root_node = NULL;
+ g_autoptr(JsonObject) root_object = NULL;
JsonObject *serialized_model = NULL;
gint n_pictures;
gint n_photosets;
gint n_groups;
gint n_tags;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
g_return_val_if_fail(FROGR_IS_CONTROLLER (self), FALSE);
g_return_val_if_fail(path, FALSE);
@@ -3118,23 +3064,18 @@ frogr_controller_save_project_to_file (FrogrController *self, const gchar *path)
serialized_model = frogr_model_serialize (model);
json_object_set_object_member (root_object, "data", serialized_model);
json_node_set_object (root_node, root_object);
- json_object_unref (root_object);
/* Create a JsonGenerator using the JsonNode as root */
json_gen = json_generator_new ();
json_generator_set_root (json_gen, root_node);
- json_node_free (root_node);
/* Save to disk */
json_generator_to_file (json_gen, path, &error);
- g_object_unref (json_gen);
if (error)
{
DEBUG ("Error serializing current state to %s: %s",
path, error->message);
- g_error_free (error);
-
return FALSE;
}
diff --git a/src/frogr-create-new-set-dialog.c b/src/frogr-create-new-set-dialog.c
index ee97f77..4bada18 100644
--- a/src/frogr-create-new-set-dialog.c
+++ b/src/frogr-create-new-set-dialog.c
@@ -104,14 +104,13 @@ _on_button_toggled (GtkToggleButton *button, gpointer data)
static gboolean
_validate_dialog_data (FrogrCreateNewSetDialog *self)
{
- gchar *title = NULL;
+ g_autofree gchar *title = NULL;
gboolean result = TRUE;
/* Validate set's title */
title = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->title_entry)));
if ((title == NULL) || g_str_equal (g_strstrip (title), ""))
result = FALSE;
- g_free (title);
return result;
}
@@ -121,8 +120,8 @@ _save_data (FrogrCreateNewSetDialog *self)
{
GtkTextIter start;
GtkTextIter end;
- gchar *title = NULL;
- gchar *description = NULL;
+ g_autofree gchar *title = NULL;
+ g_autofree gchar *description = NULL;
gboolean result = FALSE;
/* Save data */
@@ -142,10 +141,6 @@ _save_data (FrogrCreateNewSetDialog *self)
else
frogr_util_show_error_dialog (GTK_WINDOW (self), _("Missing data required"));
- /* free */
- g_free (title);
- g_free (description);
-
/* Return result */
return result;
}
@@ -157,7 +152,7 @@ _update_model (FrogrCreateNewSetDialog *self,
{
FrogrController *controller = NULL;
FrogrModel *model = NULL;
- FrogrPhotoSet *new_set = NULL;
+ g_autoptr(FrogrPhotoSet) new_set = NULL;
FrogrPicture *picture = NULL;
GSList *item = NULL;
@@ -181,7 +176,6 @@ _update_model (FrogrCreateNewSetDialog *self,
frogr_picture_set_description (picture, description);
}
}
- g_object_unref (new_set);
frogr_model_notify_changes_in_pictures (model);
}
@@ -249,15 +243,13 @@ _frogr_create_new_set_dialog_dispose (GObject *object)
if (dialog->pictures)
{
- g_slist_foreach (dialog->pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (dialog->pictures);
+ g_slist_free_full (dialog->pictures, g_object_unref);
dialog->pictures = NULL;
}
if (dialog->photosets)
{
- g_slist_foreach (dialog->photosets, (GFunc)g_object_unref, NULL);
- g_slist_free (dialog->photosets);
+ g_slist_free_full (dialog->photosets, g_object_unref);
dialog->photosets = NULL;
}
diff --git a/src/frogr-details-dialog.c b/src/frogr-details-dialog.c
index 2df560d..e17cb8c 100644
--- a/src/frogr-details-dialog.c
+++ b/src/frogr-details-dialog.c
@@ -454,18 +454,17 @@ _load_picture_from_disk (FrogrDetailsDialog *self)
n_pictures = g_slist_length (self->pictures);
if (n_pictures > 1)
{
- gchar *mpictures_str = NULL;
+ g_autofree gchar *mpictures_str = NULL;
/* Get the 'multiple pictures pixbuf' if not got yet (lazy approach) */
if (!self->mpictures_pixbuf)
{
- gchar *mpictures_full_path = NULL;
+ g_autofree gchar *mpictures_full_path = NULL;
/* Set the image for editing multiple pictures */
mpictures_full_path = g_strdup_printf ("%s/" MPICTURES_IMAGE,
frogr_util_get_app_data_dir ());
self->mpictures_pixbuf = gdk_pixbuf_new_from_file (mpictures_full_path, NULL);
- g_free (mpictures_full_path);
}
/* Just set the pixbuf in the image */
@@ -474,7 +473,6 @@ _load_picture_from_disk (FrogrDetailsDialog *self)
/* Visually indicate how many pictures are being edited */
mpictures_str = g_strdup_printf (ngettext ("(%d Picture)", "(%d Pictures)", n_pictures), n_pictures);
gtk_label_set_text (GTK_LABEL (self->mpictures_label), mpictures_str);
- g_free (mpictures_str);
/* No need to spawn any async operation, show the dialog now */
_place_picture_in_dialog_and_show (self);
@@ -482,11 +480,11 @@ _load_picture_from_disk (FrogrDetailsDialog *self)
else
{
FrogrPicture *picture = NULL;
- gchar *file_uri = NULL;
+ const gchar *file_uri = NULL;
GFile *gfile = NULL;
picture = FROGR_PICTURE (self->pictures->data);
- file_uri = (gchar *)frogr_picture_get_fileuri (picture);
+ file_uri = frogr_picture_get_fileuri (picture);
gfile = g_file_new_for_uri (file_uri);
/* Asynchronously load the picture */
@@ -501,15 +499,15 @@ _load_picture_from_disk_cb (GObject *object,
{
FrogrDetailsDialog *self = FROGR_DETAILS_DIALOG (data);
GFile *file = NULL;
- GError *error = NULL;
- gchar *contents = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autofree gchar *contents = NULL;
gsize length = 0;
file = G_FILE (object);
if (g_file_load_contents_finish (file, res, &contents, &length, NULL, &error))
{
FrogrPicture *picture = NULL;
- GdkPixbuf *pixbuf = NULL;
+ g_autoptr(GdkPixbuf) pixbuf = NULL;
picture = FROGR_PICTURE (self->pictures->data);
if (frogr_picture_is_video (picture))
@@ -518,45 +516,35 @@ _load_picture_from_disk_cb (GObject *object,
}
else
{
- gchar *path = NULL;
+ g_autofree gchar *path = NULL;
path = g_file_get_path (file);
pixbuf = frogr_util_get_pixbuf_from_image_contents ((const guchar *)contents, length,
PICTURE_WIDTH, PICTURE_HEIGHT, path, &error);
- g_free (path);
}
if (pixbuf)
- {
- gtk_image_set_from_pixbuf (GTK_IMAGE (self->picture_img), pixbuf);
- g_object_unref (pixbuf);
- }
+ gtk_image_set_from_pixbuf (GTK_IMAGE (self->picture_img), pixbuf);
/* Everything should be fine by now, show it */
_place_picture_in_dialog_and_show (self);
-
- g_free (contents);
}
/* Show error to the user and finalize dialog if needed */
if (error)
{
GtkWindow *parent_window = NULL;
- gchar *error_msg = NULL;
+ g_autofree gchar *error_msg = NULL;
parent_window = gtk_window_get_transient_for (GTK_WINDOW (self));
gtk_widget_destroy (GTK_WIDGET (self));
if (error)
- {
- error_msg = g_strdup (error->message);
- g_error_free (error);
- }
+ error_msg = g_strdup (error->message);
else
error_msg = g_strdup (_("An error happened trying to load the picture"));
frogr_util_show_error_dialog (parent_window, error_msg);
- g_free (error_msg);
}
}
@@ -853,13 +841,11 @@ _validate_dialog_data (FrogrDetailsDialog *self)
/* Mandatory fields (only if editing a single picture) */
if (g_slist_length (self->pictures) <= 1)
{
- gchar *title =
+ g_autofree gchar *title =
g_strdup (gtk_entry_get_text (GTK_ENTRY (self->title_entry)));
if ((title == NULL) || g_str_equal (g_strstrip (title), ""))
result = FALSE;
-
- g_free (title);
}
/* Validated if reached */
@@ -871,9 +857,9 @@ _save_data (FrogrDetailsDialog *self)
{
GtkTextIter start;
GtkTextIter end;
- gchar *title = NULL;
- gchar *description = NULL;
- gchar *tags = NULL;
+ g_autofree gchar *title = NULL;
+ g_autofree gchar *description = NULL;
+ g_autofree gchar *tags = NULL;
gboolean is_public;
gboolean is_friend;
gboolean is_family;
@@ -1009,11 +995,6 @@ _save_data (FrogrDetailsDialog *self)
frogr_util_show_error_dialog (GTK_WINDOW (self), _("Missing data required"));
}
- /* free */
- g_free (title);
- g_free (description);
- g_free (tags);
-
/* Return result */
return result;
}
@@ -1123,8 +1104,7 @@ _frogr_details_dialog_dispose (GObject *object)
if (dialog->pictures)
{
- g_slist_foreach (dialog->pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (dialog->pictures);
+ g_slist_free_full (dialog->pictures, g_object_unref);
dialog->pictures = NULL;
}
diff --git a/src/frogr-file-loader.c b/src/frogr-file-loader.c
index 742135d..649c367 100644
--- a/src/frogr-file-loader.c
+++ b/src/frogr-file-loader.c
@@ -135,7 +135,7 @@ static void _finish_task_and_self_destruct (FrogrFileLoader *self);
static void
_update_status_and_progress (FrogrFileLoader *self)
{
- gchar *status_text = NULL;
+ g_autofree gchar *status_text = NULL;
/* Update progress */
if (self->current_uri || self->current_picture)
@@ -143,9 +143,6 @@ _update_status_and_progress (FrogrFileLoader *self)
self->index, self->n_files);
frogr_main_view_set_status_text (self->mainview, status_text);
-
- /* Free */
- g_free (status_text);
}
static void
@@ -176,12 +173,13 @@ _load_current_file (FrogrFileLoader *self)
if (file_uri)
{
- GFile *gfile = g_file_new_for_uri (file_uri);
- GFileInfo *file_info;
+ GFile *gfile = NULL;
+ g_autoptr(GFileInfo) file_info = NULL;
gboolean valid_mime = TRUE;
/* Get file info (from this point on, use (file_info != NULL) as
a reliable way to know whether the file exists or not */
+ gfile = g_file_new_for_uri (file_uri);
file_info = g_file_query_info (gfile,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE,
@@ -210,8 +208,6 @@ _load_current_file (FrogrFileLoader *self)
}
DEBUG ("Mime detected: %s", mime_type);
}
-
- g_object_unref (file_info);
}
/* Asynchronously load the file if mime is valid */
@@ -244,9 +240,9 @@ _load_current_file_cb (GObject *object,
{
FrogrFileLoader *self = NULL;
FrogrPicture *picture = NULL;
- GFile *file = NULL;
- GError *error = NULL;
- gchar *contents = NULL;
+ g_autoptr(GFile) file = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autofree gchar *contents = NULL;
gsize length = 0;
gboolean keep_going = FALSE;
@@ -255,7 +251,7 @@ _load_current_file_cb (GObject *object,
file = G_FILE (object);
if (g_file_load_contents_finish (file, res, &contents, &length, NULL, &error))
{
- GdkPixbuf *pixbuf = NULL;
+ g_autoptr(GdkPixbuf) pixbuf = NULL;
gboolean is_video = FALSE;
/* Load the pixbuf for the video or the image */
@@ -278,24 +274,17 @@ _load_current_file_cb (GObject *object,
picture = _create_new_picture (self, file, pixbuf, is_video);
_update_picture_with_exif_data (self, contents, length, picture);
}
-
- g_object_unref (pixbuf);
}
}
else
{
/* Not able to load contents */
- gchar *file_name = g_file_get_basename (file);
+ g_autofree gchar *file_name = g_file_get_basename (file);
g_warning ("Not able to read contents from %s: %s",
file_name,
error->message);
- g_error_free (error);
- g_free (file_name);
}
- g_free (contents);
- g_object_unref (file);
-
/* Update internal status */
_advance_to_next_file (self);
@@ -355,27 +344,20 @@ _try_get_pixbuf_for_image (FrogrFileLoader *self,
gsize length)
{
GdkPixbuf *pixbuf = NULL;
- gchar *path = NULL;
- GError *error = NULL;
+ g_autofree gchar *path = NULL;
+ g_autoptr(GError) error = NULL;
path = g_file_get_path (file);
pixbuf = frogr_util_get_pixbuf_from_image_contents ((const guchar *)contents, length,
IV_THUMB_WIDTH, IV_THUMB_HEIGHT, path, &error);
- g_free (path);
-
if (error)
{
- gchar *file_name = NULL;
- gchar *msg = NULL;
+ g_autofree gchar *file_name = NULL;
+ g_autofree gchar *msg = NULL;
file_name = g_file_get_basename (file);
msg = g_strdup_printf (_("Unable to load picture %s:\n%s"), file_name, error->message);
- g_free (file_name);
-
frogr_util_show_error_dialog (GTK_WINDOW (self->mainview), msg);
- g_free (msg);
-
- g_error_free (error);
}
return pixbuf;
@@ -388,13 +370,13 @@ _try_get_pixbuf_for_video (FrogrFileLoader *self,
gsize length)
{
GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
pixbuf = frogr_util_get_pixbuf_for_video_file (file, IV_THUMB_WIDTH, IV_THUMB_HEIGHT, &error);
if (!pixbuf)
{
- gchar *file_name = NULL;
- gchar *msg = NULL;
+ g_autofree gchar *file_name = NULL;
+ g_autofree gchar *msg = NULL;
/* FIXME: We should integrate with gstreamer's codec
installer instead of just showing an error message to
@@ -402,13 +384,7 @@ _try_get_pixbuf_for_video (FrogrFileLoader *self,
file_name = g_file_get_basename (file);
msg = g_strdup_printf (_("Unable to load video %s\n"
"Please check that you have the right codec installed"), file_name);
- g_free (file_name);
-
frogr_util_show_error_dialog (GTK_WINDOW (self->mainview), msg);
- g_free (msg);
-
- if (error)
- g_error_free (error);
}
return pixbuf;
@@ -492,11 +468,11 @@ static FrogrPicture*
_create_new_picture (FrogrFileLoader *self, GFile *file, GdkPixbuf *pixbuf, gboolean is_video)
{
FrogrPicture *picture = NULL;
- GFileInfo* file_info = NULL;
- gchar *file_name = NULL;
- gchar *file_uri = NULL;
+ g_autoptr(GFileInfo) file_info = NULL;
+ g_autofree gchar *file_name = NULL;
+ g_autofree gchar *file_uri = NULL;
guint64 filesize = 0;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
/* Gather needed information */
file_info = g_file_query_info (file,
@@ -512,7 +488,6 @@ _create_new_picture (FrogrFileLoader *self, GFile *file, GdkPixbuf *pixbuf, gboo
else
{
g_warning ("Not able to read file information: %s", error->message);
- g_error_free (error);
/* Fallback if g_file_query_info() failed */
file_name = g_file_get_basename (file);
@@ -548,12 +523,6 @@ _create_new_picture (FrogrFileLoader *self, GFile *file, GdkPixbuf *pixbuf, gboo
/* FrogrPicture stores the size in KB */
frogr_picture_set_filesize (picture, filesize / 1024);
- if (file_info)
- g_object_unref (file_info);
-
- g_free (file_uri);
- g_free (file_name);
-
return picture;
}
@@ -573,7 +542,7 @@ _update_picture_with_exif_data (FrogrFileLoader *self,
exif_data = exif_loader_get_data (exif_loader);
if (exif_data)
{
- FrogrLocation *location = NULL;
+ g_autoptr(FrogrLocation) location = NULL;
ExifEntry *exif_entry = NULL;
/* Date and time for picture taken */
@@ -582,11 +551,10 @@ _update_picture_with_exif_data (FrogrFileLoader *self,
{
if (exif_entry->format == EXIF_FORMAT_ASCII)
{
- gchar *value = g_new0 (char, 20);
+ g_autofree gchar *value = g_new0 (char, 20);
exif_entry_get_value (exif_entry, value, 20);
frogr_picture_set_datetime (picture, value);
- g_free (value);
}
else
g_warning ("Found DateTime exif tag of invalid type");
@@ -595,14 +563,11 @@ _update_picture_with_exif_data (FrogrFileLoader *self,
/* Import tags from XMP metadata, if required */
if (self->import_tags)
{
- gchar *imported_tags = NULL;
+ g_autofree gchar *imported_tags = NULL;
imported_tags = import_tags_from_xmp_keywords (contents, length);
if (imported_tags)
- {
- frogr_picture_set_tags (picture, imported_tags);
- g_free (imported_tags);
- }
+ frogr_picture_set_tags (picture, imported_tags);
}
/* GPS coordinates */
@@ -611,7 +576,6 @@ _update_picture_with_exif_data (FrogrFileLoader *self,
{
/* frogr_picture_set_location takes ownership of location */
frogr_picture_set_location (picture, location);
- g_object_unref (location);
}
exif_data_unref (exif_data);
}
@@ -631,7 +595,7 @@ _check_filesize_limits (FrogrFileLoader *self, FrogrPicture *picture)
if (picture_filesize > max_filesize)
{
- gchar *msg = NULL;
+ g_autofree gchar *msg = NULL;
/* First %s is the title of the picture (filename of the file by
default). Second %s is the max allowed size for a picture to be
@@ -642,7 +606,6 @@ _check_filesize_limits (FrogrFileLoader *self, FrogrPicture *picture)
frogr_util_get_datasize_string (max_filesize));
frogr_util_show_error_dialog (GTK_WINDOW (self->mainview), msg);
- g_free (msg);
keep_going = FALSE;
}
@@ -677,7 +640,7 @@ import_tags_from_xmp_keywords (const char *buffer, size_t len)
{
const gchar *keywords_start = NULL;
const gchar *keywords_end = NULL;
- gchar *keywords_string = NULL;
+ g_autofree gchar *keywords_string = NULL;
gchar *start = NULL;
gchar *end = NULL;
gchar *result = NULL;
@@ -709,7 +672,7 @@ import_tags_from_xmp_keywords (const char *buffer, size_t len)
end = g_strrstr (keywords_string, "</rdf:li>");
if (start && end)
{
- gchar **keywords = NULL;
+ g_auto(GStrv) keywords = NULL;
gchar *keyword = NULL;
/* Get an array of strings with all the keywords */
@@ -726,11 +689,8 @@ import_tags_from_xmp_keywords (const char *buffer, size_t len)
}
result = g_strjoinv (" ", keywords);
- g_strfreev (keywords);
}
- g_free (keywords_string);
-
return result;
}
@@ -756,8 +716,7 @@ _frogr_file_loader_finalize (GObject* object)
FrogrFileLoader *self = FROGR_FILE_LOADER (object);
/* Free */
- g_slist_foreach (self->file_uris, (GFunc)g_free, NULL);
- g_slist_free (self->file_uris);
+ g_slist_free_full (self->file_uris, g_free);
G_OBJECT_CLASS (frogr_file_loader_parent_class)->finalize(object);
}
diff --git a/src/frogr-live-entry.c b/src/frogr-live-entry.c
index 252454d..13bcf72 100644
--- a/src/frogr-live-entry.c
+++ b/src/frogr-live-entry.c
@@ -87,11 +87,11 @@ _entry_list_completion_func (GtkEntryCompletion *completion, const gchar *key,
GtkTreeIter *iter, gpointer data)
{
FrogrLiveEntry *self = NULL;
- gchar *stripped_entry_text = NULL;
+ g_autofree gchar *stripped_entry_text = NULL;
+ g_autofree gchar *entry = NULL;
+ g_autofree gchar *lc_basetext = NULL;
+ g_autofree gchar *lc_entry = NULL;
gchar *basetext = NULL;
- gchar *entry = NULL;
- gchar *lc_basetext = NULL;
- gchar *lc_entry = NULL;
gint cursor_pos = 0;
gboolean matches = FALSE;
@@ -122,11 +122,6 @@ _entry_list_completion_func (GtkEntryCompletion *completion, const gchar *key,
if (g_str_has_prefix (lc_entry, lc_basetext))
matches = TRUE;
- g_free (stripped_entry_text);
- g_free (entry);
- g_free (lc_basetext);
- g_free (lc_entry);
-
return matches;
}
@@ -135,11 +130,11 @@ _completion_match_selected_cb (GtkEntryCompletion *widget, GtkTreeModel *model,
GtkTreeIter *iter, gpointer data)
{
FrogrLiveEntry *self = NULL;
- gchar *entry = NULL;
+ g_autofree gchar *entry = NULL;
+ g_autofree gchar *base_text = NULL;
+ g_autofree gchar *new_text = NULL;
const gchar *entry_text = NULL;
const gchar *matching_text = NULL;
- gchar *base_text = NULL;
- gchar *new_text = NULL;
glong entry_text_len = 0;
glong matching_text_len = 0;
@@ -162,10 +157,6 @@ _completion_match_selected_cb (GtkEntryCompletion *widget, GtkTreeModel *model,
gtk_entry_set_text (GTK_ENTRY (self), new_text);
gtk_editable_set_position (GTK_EDITABLE (self), -1);
- g_free (entry);
- g_free (base_text);
- g_free (new_text);
-
return TRUE;
}
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 3db6d94..bcc1965 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -345,8 +345,7 @@ _initialize_ui (FrogrMainView *self)
}
gtk_window_set_default_icon_list (icons);
- g_list_foreach (icons, (GFunc) g_object_unref, NULL);
- g_list_free (icons);
+ g_list_free_full (icons, g_object_unref);
/* Get widgets from GtkBuilder */
builder = gtk_builder_new ();
@@ -585,7 +584,7 @@ static void _initialize_header_bar (FrogrMainView *self)
GtkWidget *menu = NULL;
GtkWidget *menu_image = NULL;
GtkIconTheme *icon_theme = NULL;
- gchar *full_path = NULL;
+ g_autofree gchar *full_path = NULL;
self->header_bar = gtk_header_bar_new ();
@@ -604,7 +603,6 @@ static void _initialize_header_bar (FrogrMainView *self)
full_path = g_strdup_printf ("%s/" UI_MENU_BUTTON_FILE, frogr_util_get_app_data_dir ());
gtk_builder_add_from_file (self->builder, full_path, NULL);
- g_free (full_path);
menu_model = G_MENU_MODEL (gtk_builder_get_object (self->builder, "menu-button"));
extract_accels_from_menu (menu_model, self->gtk_app);
@@ -671,13 +669,12 @@ static void _initialize_menubar_and_toolbar (FrogrMainView *self)
{
GtkWidget *toolbar = NULL;
GtkToolItem *toolbar_items[7];
- gchar *full_path = NULL;
+ g_autofree gchar *full_path = NULL;
gint i;
/* Menu bar */
full_path = g_strdup_printf ("%s/" UI_MENU_BAR_FILE, frogr_util_get_app_data_dir ());
gtk_builder_add_from_file (self->builder, full_path, NULL);
- g_free (full_path);
g_action_map_add_action_entries (G_ACTION_MAP (self),
win_entries, G_N_ELEMENTS (win_entries),
@@ -755,9 +752,9 @@ _update_project_path (FrogrMainView *self, const gchar *path)
}
else
{
- GFile *file = NULL;
- GFile *dir = NULL;
- GFileInfo *file_info = NULL;
+ g_autoptr(GFile) file = NULL;
+ g_autoptr(GFile) dir = NULL;
+ g_autoptr(GFileInfo) file_info = NULL;
gchar *dir_path = NULL;
const gchar *home_dir = NULL;
@@ -776,19 +773,15 @@ _update_project_path (FrogrMainView *self, const gchar *path)
home_dir = g_get_home_dir ();
if (g_str_has_prefix (dir_path, home_dir))
{
- gchar *tmp_path = NULL;
+ g_autofree gchar *tmp_path = NULL;
tmp_path = dir_path;
dir_path = g_strdup_printf ("~%s", &dir_path[g_utf8_strlen (home_dir, -1)]);
- g_free (tmp_path);
}
self->project_dir = dir_path;
/* Finally, store the raw path too */
self->project_filepath = g_strdup (path);
-
- g_object_unref (file);
- g_object_unref (dir);
}
}
@@ -796,8 +789,8 @@ static void
_update_window_title (FrogrMainView *self, gboolean dirty)
{
#if USE_HEADER_BAR
- gchar *title = NULL;
- gchar *subtitle = NULL;
+ g_autofree gchar *title = NULL;
+ g_autofree gchar *subtitle = NULL;
title = self->project_name
? g_strdup_printf ("%s%s", (dirty ? "*" : ""), self->project_name)
@@ -810,13 +803,10 @@ _update_window_title (FrogrMainView *self, gboolean dirty)
gtk_header_bar_set_title (GTK_HEADER_BAR (self->header_bar), title);
gtk_header_bar_set_subtitle (GTK_HEADER_BAR (self->header_bar), subtitle);
- g_free (subtitle);
- g_free (title);
-
#else /* !USE_HEADER_BAR */
- gchar *session_string = NULL;
- gchar *window_title = NULL;
+ g_autofree gchar *session_string = NULL;
+ g_autofree gchar *window_title = NULL;
session_string = self->project_name
? g_strdup_printf ("%s%s (%s) - ", (dirty ? "*" : ""),
@@ -824,10 +814,7 @@ _update_window_title (FrogrMainView *self, gboolean dirty)
: g_strdup("");
window_title = g_strdup_printf ("%s%s", session_string, APP_SHORTNAME);
- g_free (session_string);
-
gtk_window_set_title (GTK_WINDOW (self), window_title);
- g_free (window_title);
#endif
}
@@ -1041,7 +1028,7 @@ _on_icon_view_drag_data_received (GtkWidget *widget,
FrogrMainView *self = NULL;
GdkAtom target;
GSList *fileuris_list = NULL;
- gchar **fileuris_array = NULL;
+ g_auto(GStrv) fileuris_array = NULL;
gint i;
self = FROGR_MAIN_VIEW (data);
@@ -1067,9 +1054,6 @@ _on_icon_view_drag_data_received (GtkWidget *widget,
/* Finish drag and drop */
gtk_drag_finish (context, TRUE, FALSE, time);
-
- /* Free */
- g_strfreev (fileuris_array);
}
gboolean
@@ -1340,13 +1324,13 @@ _on_icon_view_query_tooltip (GtkWidget *icon_view,
x, y, &bw_x, &bw_y);
if (gtk_icon_view_get_item_at_pos (GTK_ICON_VIEW (icon_view), bw_x, bw_y, &path, NULL))
{
- FrogrPicture *picture;
+ g_autoptr(FrogrPicture) picture = NULL;
GtkTreeIter iter;
- gchar *tooltip_str = NULL;
- gchar *filesize = NULL;
- gchar *filesize_str = NULL;
- gchar *filesize_markup = NULL;
- gchar *datetime_markup = NULL;
+ g_autofree gchar *tooltip_str = NULL;
+ g_autofree gchar *filesize = NULL;
+ g_autofree gchar *filesize_str = NULL;
+ g_autofree gchar *filesize_markup = NULL;
+ g_autofree gchar *datetime_markup = NULL;
const gchar *datetime = NULL;
/* Get needed information */
@@ -1365,12 +1349,11 @@ _on_icon_view_query_tooltip (GtkWidget *icon_view,
datetime = frogr_picture_get_datetime (picture);
if (datetime)
{
- gchar *datetime_str = NULL;
+ g_autofree gchar *datetime_str = NULL;
/* String showind the date and time a picture was taken */
datetime_str = g_strdup_printf (_("Taken: %s"), datetime);
datetime_markup = g_strdup_printf ("\n<i>%s</i>", datetime_str);
- g_free (datetime_str);
}
filesize_str = g_strdup_printf (_("File size: %s"), filesize);
@@ -1385,12 +1368,6 @@ _on_icon_view_query_tooltip (GtkWidget *icon_view,
/* Free memory */
gtk_tree_path_free (path);
- g_object_unref (picture);
- g_free (tooltip_str);
- g_free (filesize);
- g_free (filesize_str);
- g_free (filesize_markup);
- g_free (datetime_markup);
return TRUE;
}
@@ -1410,9 +1387,7 @@ _on_icon_view_selection_changed (GtkWidget *icon_view, gpointer data)
gtk_icon_view_get_selected_items (GTK_ICON_VIEW (self->icon_view));
len = g_list_length (selected_pictures);
-
- g_list_foreach (selected_pictures, (GFunc)gtk_tree_path_free, NULL);
- g_list_free (selected_pictures);
+ g_list_free_full (selected_pictures, (GDestroyNotify)gtk_tree_path_free);
self->n_selected_pictures = len;
@@ -1477,7 +1452,7 @@ _open_project_dialog_response_cb (GtkDialog *dialog,
if (response == GTK_RESPONSE_ACCEPT)
{
- gchar *filename = NULL;
+ g_autofree gchar *filename = NULL;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
if (filename != NULL)
@@ -1485,7 +1460,6 @@ _open_project_dialog_response_cb (GtkDialog *dialog,
/* Load from disk and update project's path */
if (frogr_controller_open_project_from_file (self->controller, filename))
_update_window_title (self, FALSE);
- g_free (filename);
}
}
@@ -1547,21 +1521,19 @@ _save_project_as_dialog_response_cb (GtkDialog *dialog, gint response, gpointer
if (response == GTK_RESPONSE_ACCEPT)
{
- gchar *filename = NULL;
+ g_autofree gchar *filename = NULL;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
if (filename != NULL)
{
- gchar *actual_filename = NULL;
+ g_autofree gchar *actual_filename = NULL;
/* Add the '.frogr' extension if not present */
actual_filename = g_str_has_suffix (filename, ".frogr")
? g_strdup (filename)
: g_strdup_printf ("%s.frogr", filename);
- g_free (filename);
_save_project_to_file (self, actual_filename);
- g_free (actual_filename);
}
}
@@ -1766,8 +1738,7 @@ _open_pictures_in_external_viewer (FrogrMainView *self)
pictures = _get_selected_pictures (self);
frogr_util_open_pictures_in_viewer (pictures);
- g_slist_foreach (pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (pictures);
+ g_slist_free_full (pictures, g_object_unref);
}
static void
@@ -1791,8 +1762,7 @@ _remove_selected_pictures (FrogrMainView *self)
_update_ui (self);
/* Free */
- g_slist_foreach (selected_pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (selected_pictures);
+ g_slist_free_full (selected_pictures, g_object_unref);
}
static void
@@ -1815,14 +1785,13 @@ static void
_reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean reversed)
{
GSList *list_as_loaded = NULL;
- GSList *current_list = NULL;
GSList *current_item = NULL;
- gint *new_order = 0;
+ g_autoptr(GSList) current_list = NULL;
+ g_autofree gchar *property_name = NULL;
+ g_autofree gint *new_order = 0;
gint current_pos = 0;
gint new_pos = 0;
- gchar *property_name = NULL;
-
self->sorting_criteria = criteria;
self->sorting_reversed = reversed;
@@ -1865,10 +1834,7 @@ _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean rever
(gchar*)property_name);
/* Update the list of pictures */
if (self->sorted_pictures)
- {
- g_slist_foreach (self->sorted_pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (self->sorted_pictures);
- }
+ g_slist_free_full (self->sorted_pictures, g_object_unref);
self->sorted_pictures = list_as_loaded;
g_slist_foreach (self->sorted_pictures, (GFunc)g_object_ref, NULL);
@@ -1884,10 +1850,6 @@ _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean rever
new_order[new_pos] = current_pos++;
}
gtk_list_store_reorder (GTK_LIST_STORE (self->tree_model), new_order);
-
- g_slist_free (current_list);
- g_free (new_order);
- g_free (property_name);
}
static void
@@ -1997,7 +1959,7 @@ _model_picture_removed (FrogrController *controller,
gboolean found = FALSE;
do
{
- FrogrPicture *picture_from_ui;
+ g_autoptr(FrogrPicture) picture_from_ui = NULL;
/* Get needed information */
gtk_tree_model_get (self->tree_model,
@@ -2016,7 +1978,6 @@ _model_picture_removed (FrogrController *controller,
found = TRUE;
}
- g_object_unref (picture_from_ui);
}
while (!found && gtk_tree_model_iter_next (tree_model, &iter));
}
@@ -2058,9 +2019,9 @@ _craft_state_description (FrogrMainView *self)
guint n_pictures = 0;
const gchar *login = NULL;
gchar *description = NULL;
- gchar *login_str = NULL;
- gchar *bandwidth_str = NULL;
- gchar *upload_size_str = NULL;
+ g_autofree gchar *login_str = NULL;
+ g_autofree gchar *bandwidth_str = NULL;
+ g_autofree gchar *upload_size_str = NULL;
gboolean is_pro = FALSE;
account = frogr_controller_get_active_account (self->controller);
@@ -2083,8 +2044,8 @@ _craft_state_description (FrogrMainView *self)
permanently show that they have 2.0 GB / 2.0 GB remaining */
if (!is_pro)
{
- gchar *remaining_bw_str = NULL;
- gchar *max_bw_str = NULL;
+ g_autofree gchar *remaining_bw_str = NULL;
+ g_autofree gchar *max_bw_str = NULL;
gulong remaining_bw;
gulong max_bw;
@@ -2105,9 +2066,6 @@ _craft_state_description (FrogrMainView *self)
remaining_bw_str,
max_bw_str);
}
-
- g_free (remaining_bw_str);
- g_free (max_bw_str);
}
/* Check size of the loaded pictures, if any */
@@ -2117,7 +2075,7 @@ _craft_state_description (FrogrMainView *self)
{
GSList *item = NULL;
gulong total_size = 0;
- gchar *total_size_str = NULL;
+ g_autofree gchar *total_size_str = NULL;
for (item = pictures; item; item = g_slist_next (item))
total_size += frogr_picture_get_filesize (FROGR_PICTURE (item->data));
@@ -2131,7 +2089,6 @@ _craft_state_description (FrogrMainView *self)
" - %d files to upload (%s)",
n_pictures),
n_pictures, total_size_str);
- g_free (total_size_str);
}
/* Build the final string */
@@ -2139,10 +2096,6 @@ _craft_state_description (FrogrMainView *self)
login_str,
(bandwidth_str ? bandwidth_str : ""),
(upload_size_str ? upload_size_str : ""));
- g_free (login_str);
- g_free (bandwidth_str);
- g_free (upload_size_str);
-
return description;
}
@@ -2179,7 +2132,7 @@ _update_sensitiveness (FrogrMainView *self)
/* gboolean has_accounts = FALSE; */
gboolean has_pics = FALSE;
gint n_selected_pics = 0;
- gchar **action_names = NULL;
+ g_auto(GStrv) action_names = NULL;
gint i = 0;
/* Set sensitiveness */
@@ -2191,7 +2144,6 @@ _update_sensitiveness (FrogrMainView *self)
action_names = g_action_group_list_actions (G_ACTION_GROUP (self));
for (i = 0; action_names[i]; i++)
_update_sensitiveness_for_action (self, action_names[i], FALSE);
- g_strfreev (action_names);
break;
case FROGR_STATE_IDLE:
@@ -2253,8 +2205,7 @@ _frogr_main_view_dispose (GObject *object)
if (self->sorted_pictures)
{
- g_slist_foreach (self->sorted_pictures, (GFunc)g_object_unref, NULL);
- g_slist_free (self->sorted_pictures);
+ g_slist_free_full (self->sorted_pictures, g_object_unref);
self->sorted_pictures = NULL;
}
diff --git a/src/frogr-model.c b/src/frogr-model.c
index 1239d76..df32da4 100644
--- a/src/frogr-model.c
+++ b/src/frogr-model.c
@@ -89,8 +89,7 @@ _remove_remote_photosets (FrogrModel *self)
g_hash_table_remove (self->sets_table, id);
}
- g_slist_foreach (self->remote_sets, (GFunc)g_object_unref, NULL);
- g_slist_free (self->remote_sets);
+ g_slist_free_full (self->remote_sets, g_object_unref);
self->remote_sets = NULL;
}
@@ -112,8 +111,7 @@ _remove_local_photosets (FrogrModel *self)
g_hash_table_remove (self->sets_table, frogr_photoset_get_local_id (set));
}
- g_slist_foreach (self->local_sets, (GFunc)g_object_unref, NULL);
- g_slist_free (self->local_sets);
+ g_slist_free_full (self->local_sets, g_object_unref);
self->local_sets = NULL;
}
@@ -163,8 +161,7 @@ _remove_groups (FrogrModel *self)
if (self->groups)
{
- g_slist_foreach (self->groups, (GFunc)g_object_unref, NULL);
- g_slist_free (self->groups);
+ g_slist_free_full (self->groups, g_object_unref);
self->groups = NULL;
}
@@ -180,8 +177,7 @@ _remove_remote_tags (FrogrModel *self)
if (!self->remote_tags)
return;
- g_slist_foreach (self->remote_tags, (GFunc)g_free, NULL);
- g_slist_free (self->remote_tags);
+ g_slist_free_full (self->remote_tags, g_free);
self->remote_tags = NULL;
}
@@ -193,8 +189,7 @@ _remove_local_tags (FrogrModel *self)
if (!self->local_tags)
return;
- g_slist_foreach (self->local_tags, (GFunc)g_free, NULL);
- g_slist_free (self->local_tags);
+ g_slist_free_full (self->local_tags, g_free);
self->local_tags = NULL;
}
@@ -606,9 +601,7 @@ frogr_model_remove_remote_tags (FrogrModel *self)
{
g_return_if_fail(FROGR_IS_MODEL (self));
- g_slist_foreach (self->remote_tags, (GFunc)g_free, NULL);
- g_slist_free (self->remote_tags);
-
+ g_slist_free_full (self->remote_tags, g_free);
self->remote_tags = NULL;
}
@@ -616,7 +609,7 @@ void
frogr_model_add_local_tags_from_string (FrogrModel *self,
const gchar *tags_string)
{
- gchar *stripped_tags = NULL;
+ g_autofree gchar *stripped_tags = NULL;
gboolean added_new_tags = FALSE;
g_return_if_fail(FROGR_IS_MODEL (self));
@@ -627,7 +620,7 @@ frogr_model_add_local_tags_from_string (FrogrModel *self,
stripped_tags = g_strstrip (g_strdup (tags_string));
if (!g_str_equal (stripped_tags, ""))
{
- gchar **tags_array = NULL;
+ g_auto(GStrv) tags_array = NULL;
gchar *tag;
gint i;
@@ -645,11 +638,9 @@ frogr_model_add_local_tags_from_string (FrogrModel *self,
g_free (tag);
}
- g_strfreev (tags_array);
self->local_tags = g_slist_sort (self->local_tags, (GCompareFunc)g_strcmp0);
}
- g_free (stripped_tags);
if (added_new_tags)
g_signal_emit (self, signals[MODEL_CHANGED], 0);
diff --git a/src/frogr-photoset.c b/src/frogr-photoset.c
index 18d400e..1ece487 100644
--- a/src/frogr-photoset.c
+++ b/src/frogr-photoset.c
@@ -292,7 +292,7 @@ frogr_photoset_new_local (const gchar *title,
const gchar *description)
{
FrogrPhotoSet *new_set;
- gchar *id;
+ g_autofree gchar *id = NULL;
g_return_val_if_fail (title, NULL);
g_return_val_if_fail (description, NULL);
@@ -302,7 +302,6 @@ frogr_photoset_new_local (const gchar *title,
/* We always need to have an id in locally created photosets */
id = _create_temporary_id_for_photoset ();
frogr_photoset_set_local_id (new_set, id);
- g_free (id);
return new_set;
}
diff --git a/src/frogr-picture.c b/src/frogr-picture.c
index f36e371..c158ced 100644
--- a/src/frogr-picture.c
+++ b/src/frogr-picture.c
@@ -140,10 +140,10 @@ _add_tags_to_tags_list (FrogrPicture *self,
/* Check if valid data is passed to the function */
if (tags_string != NULL)
{
- gchar *stripped_tags = g_strstrip (g_strdup (tags_string));
+ g_autofree gchar *stripped_tags = g_strstrip (g_strdup (tags_string));
if (!g_str_equal (stripped_tags, ""))
{
- gchar **tags_array = NULL;
+ g_auto(GStrv) tags_array = NULL;
gchar *tag;
gint i;
@@ -156,11 +156,7 @@ _add_tags_to_tags_list (FrogrPicture *self,
if (!g_str_equal (tag, "") && !_tag_is_set (self, tag))
self->tags_list = g_slist_append (self->tags_list, tag);
}
-
- /* Free */
- g_strfreev (tags_array);
}
- g_free (stripped_tags);
/* Update internal tags string */
_update_tags_string (self);
@@ -502,15 +498,13 @@ _frogr_picture_dispose (GObject* object)
if (self->photosets)
{
- g_slist_foreach (self->photosets, (GFunc) g_object_unref, NULL);
- g_slist_free (self->photosets);
+ g_slist_free_full (self->photosets, g_object_unref);
self->photosets = NULL;
}
if (self->groups)
{
- g_slist_foreach (self->groups, (GFunc) g_object_unref, NULL);
- g_slist_free (self->groups);
+ g_slist_free_full (self->groups, g_object_unref);
self->groups = NULL;
}
@@ -532,8 +526,7 @@ _frogr_picture_finalize (GObject* object)
g_free (self->datetime);
/* free GSList of tags */
- g_slist_foreach (self->tags_list, (GFunc) g_free, NULL);
- g_slist_free (self->tags_list);
+ g_slist_free_full (self->tags_list, g_free);
/* call super class */
G_OBJECT_CLASS (frogr_picture_parent_class)->finalize(object);
@@ -852,8 +845,7 @@ frogr_picture_set_tags (FrogrPicture *self, const gchar *tags_string)
g_return_if_fail(FROGR_IS_PICTURE(self));
/* First remove all the previous tags list */
- g_slist_foreach (self->tags_list, (GFunc) g_free, NULL);
- g_slist_free (self->tags_list);
+ g_slist_free_full (self->tags_list, g_free);
self->tags_list = NULL;
/* Add to internal tags_list */
@@ -1091,9 +1083,7 @@ frogr_picture_set_photosets (FrogrPicture *self, GSList *photosets)
g_return_if_fail(FROGR_IS_PICTURE(self));
/* First remove all the previous sets list */
- g_slist_foreach (self->photosets, (GFunc) g_object_unref, NULL);
- g_slist_free (self->photosets);
-
+ g_slist_free_full (self->photosets, g_object_unref);
self->photosets = photosets;
}
@@ -1143,9 +1133,7 @@ frogr_picture_set_groups (FrogrPicture *self, GSList *groups)
g_return_if_fail(FROGR_IS_PICTURE(self));
/* First remove all the previous groups list */
- g_slist_foreach (self->groups, (GFunc) g_object_unref, NULL);
- g_slist_free (self->groups);
-
+ g_slist_free_full (self->groups, g_object_unref);
self->groups = groups;
}
@@ -1220,8 +1208,8 @@ frogr_picture_compare_by_property (FrogrPicture *self, FrogrPicture *other,
{
const gchar *str1 = NULL;
const gchar *str2 = NULL;
- gchar *str1_cf = NULL;
- gchar *str2_cf = NULL;
+ g_autofree gchar *str1_cf = NULL;
+ g_autofree gchar *str2_cf = NULL;
/* Comparison of strings require some additional work to take
into account the different rules for each locale */
@@ -1232,9 +1220,6 @@ frogr_picture_compare_by_property (FrogrPicture *self, FrogrPicture *other,
str2_cf = g_utf8_casefold (str2 ? str2 : "", -1);
result = g_utf8_collate (str1_cf, str2_cf);
-
- g_free (str1_cf);
- g_free (str2_cf);
}
else
g_warning ("Unsupported type for property used for sorting");
diff --git a/src/frogr-settings-dialog.c b/src/frogr-settings-dialog.c
index 5429dc7..d00351a 100644
--- a/src/frogr-settings-dialog.c
+++ b/src/frogr-settings-dialog.c
@@ -332,7 +332,7 @@ _add_connection_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
GtkWidget *cbutton = NULL;
GtkWidget *label = NULL;
GtkWidget *entry = NULL;
- gchar *markup = NULL;
+ g_autofree gchar *markup = NULL;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
@@ -343,7 +343,6 @@ _add_connection_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
markup = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
_("Proxy Settings"));
gtk_label_set_markup (GTK_LABEL (label), markup);
- g_free (markup);
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
@@ -432,7 +431,7 @@ _add_misc_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
GtkWidget *vbox = NULL;
GtkWidget *box = NULL;
GtkWidget *label = NULL;
- gchar *markup = NULL;
+ g_autofree gchar *markup = NULL;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
@@ -443,7 +442,6 @@ _add_misc_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
markup = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
_("Other options"));
gtk_label_set_markup (GTK_LABEL (label), markup);
- g_free (markup);
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
diff --git a/src/frogr-util.c b/src/frogr-util.c
index 127516e..fcd1db8 100644
--- a/src/frogr-util.c
+++ b/src/frogr-util.c
@@ -52,15 +52,12 @@
static gboolean
_spawn_command (const gchar* cmd)
{
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
if (!g_spawn_command_line_async (cmd, &error))
{
if (error)
- {
- DEBUG ("Error spawning command '%s': %s", cmd, error->message);
- g_error_free (error);
- }
+ DEBUG ("Error spawning command '%s': %s", cmd, error->message);
return FALSE;
}
@@ -91,7 +88,7 @@ gchar *
_get_uris_string_from_list (GList *uris_list)
{
GList *current_uri = NULL;
- gchar **uris_array = NULL;
+ g_auto(GStrv) uris_array = NULL;
gchar *uris_str = NULL;
gint n_uris = 0;
gint i = 0;
@@ -105,7 +102,6 @@ _get_uris_string_from_list (GList *uris_list)
uris_array[i++] = (gchar *) (current_uri->data);
uris_str = g_strjoinv (" ", uris_array);
- g_free (uris_array);
return uris_str;
}
@@ -113,7 +109,7 @@ _get_uris_string_from_list (GList *uris_list)
static void
_open_uris_with_app_info (GList *uris_list, GAppInfo *app_info)
{
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
/* Early return */
if (!uris_list)
@@ -122,25 +118,18 @@ _open_uris_with_app_info (GList *uris_list, GAppInfo *app_info)
if (!app_info || !g_app_info_launch_uris (app_info, uris_list, NULL, &error))
{
/* The default app didn't succeed, so try 'xdg-open' / 'open' */
- gchar *command = NULL;
- gchar *uris = NULL;
+ g_autofree gchar *command = NULL;
+ g_autofree gchar *uris = NULL;
uris = _get_uris_string_from_list (uris_list);
command = g_strdup_printf ("gvfs-open %s", uris);
_spawn_command (command);
if (error)
- {
- DEBUG ("Error opening URI(s) %s: %s", uris, error->message);
- g_error_free (error);
- }
-
- g_free (command);
- g_free (uris);
+ DEBUG ("Error opening URI(s) %s: %s", uris, error->message);
}
- g_list_foreach (uris_list, (GFunc) g_free, NULL);
- g_list_free (uris_list);
+ g_list_free_full (uris_list, g_free);
}
void
@@ -302,7 +291,7 @@ _get_corrected_pixbuf (GdkPixbuf *pixbuf, gint max_width, gint max_height)
static GdkPixbuf *
_get_pixbuf_from_image_contents (const guchar *contents, gsize length, const gchar *filepath, GError
**out_error)
{
- GdkPixbufLoader *pixbuf_loader = NULL;
+ g_autoptr(GdkPixbufLoader) pixbuf_loader = NULL;
GdkPixbuf *pixbuf = NULL;
GError *error = NULL;
@@ -335,7 +324,6 @@ _get_pixbuf_from_image_contents (const guchar *contents, gsize length, const gch
/* Keep the pixbuf before destroying the loader */
if (pixbuf)
g_object_ref (pixbuf);
- g_object_unref (pixbuf_loader);
return pixbuf;
}
@@ -358,8 +346,8 @@ _get_pixbuf_from_video_file (GFile *file, GError **out_error)
gint width, height;
gboolean res;
#endif
- gchar *file_uri;
- gchar *descr;
+ g_autofree gchar *file_uri = NULL;
+ g_autofree gchar *descr = NULL;
gint64 duration, position;
GError *error = NULL;
@@ -373,10 +361,7 @@ _get_pixbuf_from_video_file (GFile *file, GError **out_error)
" appsink name=sink caps=\"" CAPS "\"", file_uri);
#endif
- g_free (file_uri);
-
pipeline = gst_parse_launch (descr, &error);
- g_free (descr);
if (error != NULL) {
DEBUG ("Could not construct pipeline: %s\n", error->message);
@@ -529,8 +514,8 @@ frogr_util_get_datasize_string (gulong datasize)
if (datasize != G_MAXULONG)
{
+ g_autofree gchar *unit_str = NULL;
gfloat datasize_float = G_MAXFLOAT;
- gchar *unit_str = NULL;
int n_divisions = 0;
datasize_float = datasize;
@@ -556,10 +541,7 @@ frogr_util_get_datasize_string (gulong datasize)
}
if (unit_str)
- {
- result = g_strdup_printf ("%.1f %s", datasize_float, unit_str);
- g_free (unit_str);
- }
+ result = g_strdup_printf ("%.1f %s", datasize_float, unit_str);
}
return result;
diff --git a/src/main.c b/src/main.c
index 461f548..ca81911 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,18 +40,15 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL;
int
main (int argc, char **argv)
{
- FrogrController *controller = NULL;
+ g_autoptr(FrogrController) controller = NULL;
int status;
#if HAVE_GSTREAMER
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
/* Initialize gstreamer before using any other GLib function */
gst_init_check (&argc, &argv, &error);
if (error)
- {
- DEBUG ("Gstreamer could not be initialized: %s", error->message);
- g_error_free (error);
- }
+ DEBUG ("Gstreamer could not be initialized: %s", error->message);
#endif
#if GCRYPT_VERSION_NUMBER < 0x010600
@@ -78,7 +75,6 @@ main (int argc, char **argv)
controller = frogr_controller_get_instance ();
status = frogr_controller_run_app (controller, argc, argv);
- g_object_unref (controller);
/* cleanup libxml2 library */
xmlCleanupParser();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]