[gtksourceview] Use g_clear_error() at some other places



commit f66ae6a5054f552fee6da809f7a6d8d7f50f5397
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jun 13 11:39:45 2016 +0200

    Use g_clear_error() at some other places
    
    Just before a return it is not necessary, g_error_free() is sufficient.
    But g_clear_error() is better because if the code is modified and the
    return is removed, we need to not forget setting error to NULL. With
    g_clear_error(), it prevents such easily-avoidable problems.

 gtksourceview/gtksourceencoding.c          |    3 +--
 gtksourceview/gtksourcelanguage-parser-2.c |    5 ++---
 2 files changed, 3 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/gtksourceencoding.c b/gtksourceview/gtksourceencoding.c
index 2df70f5..d0abceb 100644
--- a/gtksourceview/gtksourceencoding.c
+++ b/gtksourceview/gtksourceencoding.c
@@ -657,8 +657,7 @@ gtk_source_encoding_get_default_candidates (void)
                           encodings_str_translated,
                           error->message);
 
-               g_error_free (error);
-               error = NULL;
+               g_clear_error (&error);
 
                encodings_variant = g_variant_parse (G_VARIANT_TYPE_STRING_ARRAY,
                                                     encodings_str,
diff --git a/gtksourceview/gtksourcelanguage-parser-2.c b/gtksourceview/gtksourcelanguage-parser-2.c
index 9a4c914..90510fe 100644
--- a/gtksourceview/gtksourcelanguage-parser-2.c
+++ b/gtksourceview/gtksourcelanguage-parser-2.c
@@ -1755,8 +1755,7 @@ parser_state_destroy (ParserState *parser_state)
        if (parser_state->reader != NULL)
                xmlFreeTextReader (parser_state->reader);
 
-       if (parser_state->error != NULL)
-               g_error_free (parser_state->error);
+       g_clear_error (&parser_state->error);
 
        g_queue_free (parser_state->curr_parents);
        g_free (parser_state->current_lang_id);
@@ -1837,7 +1836,7 @@ _gtk_source_language_file_parse_version2 (GtkSourceLanguage       *language,
        {
                g_warning ("Failed to load '%s': %s",
                           filename, error->message);
-               g_error_free (error);
+               g_clear_error (&error);
                return FALSE;
        }
 


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