[evolution] Fix few memory leaks from webkit_dom_element_get_attribute() calls



commit 453259d2b29d2684176f3870d4616ca81b19c69b
Author: Milan Crha <mcrha redhat com>
Date:   Wed Mar 25 11:32:12 2015 +0100

    Fix few memory leaks from webkit_dom_element_get_attribute() calls

 e-util/e-html-editor-image-dialog.c |    2 +-
 e-util/e-html-editor-selection.c    |    2 +-
 e-util/e-html-editor-view.c         |   13 ++++++++++---
 3 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/e-util/e-html-editor-image-dialog.c b/e-util/e-html-editor-image-dialog.c
index 62ffa95..7290235 100644
--- a/e-util/e-html-editor-image-dialog.c
+++ b/e-util/e-html-editor-image-dialog.c
@@ -402,13 +402,13 @@ html_editor_image_dialog_show (GtkWidget *widget)
                        GTK_FILE_CHOOSER (dialog->priv->file_chooser), tmp);
                gtk_widget_set_sensitive (
                        GTK_WIDGET (dialog->priv->file_chooser), TRUE);
-               g_free (tmp);
        } else {
                gtk_file_chooser_set_uri (
                        GTK_FILE_CHOOSER (dialog->priv->file_chooser), "");
                gtk_widget_set_sensitive (
                        GTK_WIDGET (dialog->priv->file_chooser), FALSE);
        }
+       g_free (tmp);
 
        tmp = webkit_dom_html_image_element_get_alt (dialog->priv->image);
        gtk_entry_set_text (GTK_ENTRY (dialog->priv->description_edit), tmp ? tmp : "");
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 24d0f26..2fa29de 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -2009,7 +2009,7 @@ get_citation_level (WebKitDOMNode *node)
 static gboolean
 is_citation_node (WebKitDOMNode *node)
 {
-       char *value;
+       gchar *value;
 
        if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node))
                return FALSE;
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index a84dc78..ffc222b 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -907,7 +907,7 @@ e_html_editor_view_quote_plain_text_element_after_wrapping (WebKitDOMDocument *d
 static gboolean
 is_citation_node (WebKitDOMNode *node)
 {
-       char *value;
+       gchar *value;
 
        if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node))
                return FALSE;
@@ -1172,7 +1172,7 @@ set_base64_to_element_attribute (EHTMLEditorView *view,
 
        attribute_value = webkit_dom_element_get_attribute (element, attribute);
 
-       if ((base64_src = g_hash_table_lookup (view->priv->inline_images, attribute_value)) != NULL) {
+       if (attribute_value && (base64_src = g_hash_table_lookup (view->priv->inline_images, 
attribute_value)) != NULL) {
                const gchar *base64_data = strstr (base64_src, ";") + 1;
                gchar *name;
                glong name_length;
@@ -1188,6 +1188,8 @@ set_base64_to_element_attribute (EHTMLEditorView *view,
 
                g_free (name);
        }
+
+       g_free (attribute_value);
 }
 
 static void
@@ -8875,6 +8877,7 @@ html_editor_view_load_status_changed (EHTMLEditorView *view)
        WebKitDOMDOMWindow *dom_window;
        WebKitDOMHTMLElement *body;
        WebKitLoadStatus status;
+       gchar *data_evo_draft;
 
        status = webkit_web_view_get_load_status (WEBKIT_WEB_VIEW (view));
        if (status != WEBKIT_LOAD_FINISHED)
@@ -8929,7 +8932,8 @@ html_editor_view_load_status_changed (EHTMLEditorView *view)
        move_elements_to_body (document);
        repair_gmail_blockquotes (document);
 
-       if (webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (body), "data-evo-draft")) {
+       data_evo_draft = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (body), "data-evo-draft");
+       if (data_evo_draft) {
                /* Restore the selection how it was when the draft was saved */
                e_html_editor_selection_move_caret_into_element (
                        document, WEBKIT_DOM_ELEMENT (body), FALSE);
@@ -8938,6 +8942,8 @@ html_editor_view_load_status_changed (EHTMLEditorView *view)
                e_html_editor_view_remove_embed_styles (view);
        }
 
+       g_free (data_evo_draft);
+
        /* The composer body could be empty in some case (loading an empty string
         * or empty HTML. In that case create the initial paragraph. */
        if (!webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body))) {
@@ -9031,6 +9037,7 @@ rename_attribute (WebKitDOMElement *element,
        if (value)
                webkit_dom_element_set_attribute (element, to, value, NULL);
        webkit_dom_element_remove_attribute (element, from);
+       g_free (value);
 }
 
 static void


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