[evolution/webkit-composer] Fix more leaks in webkit-composer.



commit fedd3c30007bdb4522cd0ab749f269b811360220
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Sep 20 08:28:20 2013 +0200

    Fix more leaks in webkit-composer.

 composer/e-composer-private.c |    3 +-
 e-util/e-editor-selection.c   |   65 ++++++++++++++++++++++++++--------------
 e-util/e-editor-widget.c      |   32 ++++++++++++++------
 e-util/e-web-view.c           |   32 ++++++++++++++------
 4 files changed, 89 insertions(+), 43 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 43108a9..4961c20 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -1049,8 +1049,9 @@ insert:
                /* When we are editing a message with signature we need to set active
                 * signature id in signature combo box otherwise no signature will be added */
                if (composer->priv->is_from_message) {
-                       const gchar *name =  webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), 
"name");
+                       gchar *name = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "name");
                        gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo_box), name);
+                       g_free (name);
                }
 
                if (id && (strlen (id) == 1) && (*id == '1')) {
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index c9982ea..7d38158 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -1647,8 +1647,7 @@ gboolean
 e_editor_selection_is_citation (EEditorSelection *selection)
 {
        gboolean ret_val;
-       const gchar *text_content;
-       gchar *value;
+       gchar *value, *text_content;
        WebKitDOMNode *node;
        WebKitDOMRange *range;
 
@@ -1663,11 +1662,14 @@ e_editor_selection_is_citation (EEditorSelection *selection)
        if (WEBKIT_DOM_IS_TEXT (node))
                return FALSE;
 
-       text_content = webkit_dom_node_get_text_content (node);
        /* If we are changing the format of block we have to re-set bold property,
         * otherwise it will be turned off because of no text in composer */
-       if (g_strcmp0 (text_content, "") == 0)
+       text_content = webkit_dom_node_get_text_content (node);
+       if (g_strcmp0 (text_content, "") == 0) {
+               g_free (text_content);
                return FALSE;
+       }
+       g_free (text_content);
 
        value = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "type");
 
@@ -1762,8 +1764,7 @@ gboolean
 e_editor_selection_is_bold (EEditorSelection *selection)
 {
        gboolean ret_val;
-       const gchar *text_content;
-       gchar *value;
+       gchar *value, *text_content;
        EEditorWidget *editor_widget;
        WebKitDOMCSSStyleDeclaration *style;
        WebKitDOMDocument *document;
@@ -1788,8 +1789,11 @@ e_editor_selection_is_bold (EEditorSelection *selection)
        /* If we are changing the format of block we have to re-set bold property,
         * otherwise it will be turned off because of no text in composer */
        text_content = webkit_dom_node_get_text_content (node);
-       if (g_strcmp0 (text_content, "") == 0)
+       if (g_strcmp0 (text_content, "") == 0) {
+               g_free (text_content);
                return selection->priv->is_bold;
+       }
+       g_free (text_content);
 
        style = webkit_dom_dom_window_get_computed_style (
                        window, webkit_dom_node_get_parent_element (node), NULL);
@@ -1850,8 +1854,7 @@ gboolean
 e_editor_selection_is_italic (EEditorSelection *selection)
 {
        gboolean ret_val;
-       const gchar *text_content;
-       gchar *value;
+       gchar *value, *text_content;
        EEditorWidget *editor_widget;
        WebKitDOMCSSStyleDeclaration *style;
        WebKitDOMDocument *document;
@@ -1876,8 +1879,11 @@ e_editor_selection_is_italic (EEditorSelection *selection)
        /* If we are changing the format of block we have to re-set italic property,
         * otherwise it will be turned off because of no text in composer */
        text_content = webkit_dom_node_get_text_content (node);
-       if (g_strcmp0 (text_content, "") == 0)
+       if (g_strcmp0 (text_content, "") == 0) {
+               g_free (text_content);
                return selection->priv->is_italic;
+       }
+       g_free (text_content);
 
        style = webkit_dom_dom_window_get_computed_style (
                        window, webkit_dom_node_get_parent_element (node), NULL);
@@ -1939,7 +1945,7 @@ e_editor_selection_is_monospaced (EEditorSelection *selection)
 {
        WebKitDOMRange *range;
        WebKitDOMNode *node;
-       const gchar *text_content;
+       gchar *text_content;
 
        g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), FALSE);
 
@@ -1951,8 +1957,11 @@ e_editor_selection_is_monospaced (EEditorSelection *selection)
        /* If we are changing the format of block we have to re-set monospaced property,
         * otherwise it will be turned off because of no text in composer */
        text_content = webkit_dom_node_get_text_content (node);
-       if (g_strcmp0 (text_content, "") == 0)
+       if (g_strcmp0 (text_content, "") == 0) {
+               g_free (text_content);
                return selection->priv->is_monospaced;
+       }
+       g_free (text_content);
 
        return get_has_style (selection, "tt");
 }
@@ -2178,8 +2187,7 @@ gboolean
 e_editor_selection_is_strike_through (EEditorSelection *selection)
 {
        gboolean ret_val;
-       const gchar *text_content;
-       gchar *value;
+       gchar *value, *text_content;
        EEditorWidget *editor_widget;
        WebKitDOMCSSStyleDeclaration *style;
        WebKitDOMDocument *document;
@@ -2204,8 +2212,11 @@ e_editor_selection_is_strike_through (EEditorSelection *selection)
        /* If we are changing the format of block we have to re-set strike-through property,
         * otherwise it will be turned off because of no text in composer */
        text_content = webkit_dom_node_get_text_content (node);
-       if (g_strcmp0 (text_content, "") == 0)
-               return selection->priv->is_strike_through;
+       if (g_strcmp0 (text_content, "") == 0) {
+               g_free (text_content);
+               return selection->priv->is_monospaced;
+       }
+       g_free (text_content);
 
        style = webkit_dom_dom_window_get_computed_style (
                        window, webkit_dom_node_get_parent_element (node), NULL);
@@ -2402,8 +2413,7 @@ gboolean
 e_editor_selection_is_underline (EEditorSelection *selection)
 {
        gboolean ret_val;
-       const gchar *text_content;
-       gchar *value;
+       gchar *value, *text_content;
        EEditorWidget *editor_widget;
        WebKitDOMCSSStyleDeclaration *style;
        WebKitDOMDocument *document;
@@ -2428,8 +2438,11 @@ e_editor_selection_is_underline (EEditorSelection *selection)
        /* If we are changing the format of block we have to re-set underline property,
         * otherwise it will be turned off because of no text in composer */
        text_content = webkit_dom_node_get_text_content (node);
-       if (g_strcmp0 (text_content, "") == 0)
+       if (g_strcmp0 (text_content, "") == 0) {
+               g_free (text_content);
                return selection->priv->is_underline;
+       }
+       g_free (text_content);
 
        style = webkit_dom_dom_window_get_computed_style (
                        window, webkit_dom_node_get_parent_element (node), NULL);
@@ -3203,7 +3216,7 @@ e_editor_selection_wrap_lines (EEditorSelection *selection,
                WebKitDOMNode *parent;
                WebKitDOMNode *paragraph;
                gulong start_offset;
-               const gchar *text_content;
+               gchar *text_content;
 
                /* We need to save caret position and restore it after
                 * wrapping the selection, but we need to save it before we
@@ -3281,8 +3294,10 @@ e_editor_selection_wrap_lines (EEditorSelection *selection,
                                gchar *node_text;
 
                                regex = g_regex_new (UNICODE_HIDDEN_SPACE, 0, 0, NULL);
-                               if (!regex)
+                               if (!regex) {
+                                       g_free (text_content);
                                        return;
+                               }
 
                                node_text = webkit_dom_character_data_get_data (WEBKIT_DOM_CHARACTER_DATA 
(child));
                                webkit_dom_character_data_set_data (
@@ -3294,6 +3309,7 @@ e_editor_selection_wrap_lines (EEditorSelection *selection,
                                g_regex_unref (regex);
                        }
                }
+               g_free (text_content);
 
                if (previously_wrapped) {
                        /* If we are on the beginning of line we need to remember it */
@@ -3384,12 +3400,15 @@ e_editor_selection_wrap_lines (EEditorSelection *selection,
                        list = webkit_dom_document_query_selector_all (document, "div.-x-evo-paragraph, 
p.-x-evo-paragraph", NULL);
                        for (ii = 0; ii < webkit_dom_node_list_get_length (list); ii++) {
                                WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
-                               const gchar *text_content;
+                               gchar *text_content;
 
                                /* Select elements that actualy have some text content */
                                text_content = webkit_dom_node_get_text_content (node);
-                               if (g_utf8_strlen (text_content, -1) == 0)
+                               if (g_utf8_strlen (text_content, -1) == 0) {
+                                       g_free (text_content);
                                        continue;
+                               }
+                               g_free (text_content);
 
                                if (signature) {
                                        if (!webkit_dom_node_contains (node, signature) &&
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index 031f31d..dc4f2c8 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -464,12 +464,14 @@ editor_widget_check_magic_links (EEditorWidget *widget,
                                WEBKIT_DOM_HTML_ANCHOR_ELEMENT (parent));
 
                if (appending_to_link) {
-                       const gchar *inner_text;
+                       gchar *inner_text;
+
                        inner_text =
                                webkit_dom_html_element_get_inner_text (
                                        WEBKIT_DOM_HTML_ELEMENT (parent)),
 
                        text = g_strconcat (inner_text, text_to_append, NULL);
+                       g_free (inner_text);
                } else
                        text = webkit_dom_html_element_get_inner_text (
                                        WEBKIT_DOM_HTML_ELEMENT (parent));
@@ -1055,7 +1057,7 @@ editor_widget_key_release_event (GtkWidget *widget,
                node = webkit_dom_range_get_end_container (range, NULL);
 
                if (WEBKIT_DOM_IS_TEXT (node)) {
-                       const gchar *text;
+                       gchar *text;
 
                        text = webkit_dom_node_get_text_content (node);
 
@@ -1067,6 +1069,7 @@ editor_widget_key_release_event (GtkWidget *widget,
                                if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (prev_sibling))
                                        editor_widget_check_magic_links (editor_widget, range, FALSE, event);
                        }
+                       g_free (text);
                }
        }
 
@@ -1580,7 +1583,7 @@ e_editor_widget_set_changed (EEditorWidget *widget,
 static gboolean
 is_citation_node (WebKitDOMNode *node)
 {
-       const gchar *value;
+       char *value;
 
        if (node && !WEBKIT_DOM_IS_HTML_ELEMENT (node))
                return FALSE;
@@ -1591,10 +1594,13 @@ is_citation_node (WebKitDOMNode *node)
        value = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "type");
 
        /* citation == <blockquote type='cite'> */
-       if (g_strcmp0 (value, "cite") == 0)
+       if (g_strcmp0 (value, "cite") == 0) {
+               g_free (value);
                return TRUE;
-       else
+       } else {
+               g_free (value);
                return FALSE;
+       }
 }
 
 static void
@@ -1602,7 +1608,7 @@ insert_quote_symbols (WebKitDOMHTMLElement *element,
                       gint quote_level,
                       gboolean force_insert)
 {
-       const gchar *text;
+       gchar *text;
        gint ii;
        GString *output;
        gchar *indent;
@@ -1678,6 +1684,7 @@ insert_quote_symbols (WebKitDOMHTMLElement *element,
        webkit_dom_html_element_set_inner_html (element, output->str, NULL);
 
        g_free (indent);
+       g_free (text);
        g_string_free (output, TRUE);
 }
 
@@ -1695,7 +1702,7 @@ quote_node (WebKitDOMDocument *document,
                WebKitDOMNode *parent;
                WebKitDOMNode *node_clone;
                WebKitDOMNode *prev_sibling;
-               const gchar *text_content;
+               gchar *text_content;
                gboolean force_insert = FALSE;
 
                text_content = webkit_dom_node_get_text_content (node);
@@ -1707,6 +1714,7 @@ quote_node (WebKitDOMDocument *document,
                                parent,
                                node,
                                NULL);
+                       g_free (text_content);
                        return;
                }
 
@@ -1745,6 +1753,7 @@ quote_node (WebKitDOMDocument *document,
                        WEBKIT_DOM_NODE (wrapper),
                        node,
                        NULL);
+               g_free (text_content);
        } else if (WEBKIT_DOM_IS_HTML_ELEMENT (node))
                insert_quote_symbols (WEBKIT_DOM_HTML_ELEMENT (node), quote_level, FALSE);
 }
@@ -1788,7 +1797,7 @@ quote_plain_text_recursive (WebKitDOMDocument *document,
                                 * modifications * of it's inner text */
                                if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (node)) {
                                        WebKitDOMNode *next_sibling;
-                                       const gchar *text_content;
+                                       gchar *text_content;
 
                                        next_sibling = webkit_dom_node_get_next_sibling (node);
                                        text_content = webkit_dom_node_get_text_content (next_sibling);
@@ -1808,6 +1817,7 @@ quote_plain_text_recursive (WebKitDOMDocument *document,
                                                        next_sibling, NULL);
                                        }
                                        move_next = TRUE;
+                                       g_free (text_content);
 
                                        goto next_node;
                                }
@@ -2058,7 +2068,7 @@ process_elements (WebKitDOMNode *node,
 
                                        for (jj = 0; jj < length; jj++) {
                                                WebKitDOMNode *quoted_node;
-                                               const gchar *text_content;
+                                               gchar *text_content;
 
                                                quoted_node = webkit_dom_node_list_item (list, jj);
                                                text_content = webkit_dom_node_get_text_content (quoted_node);
@@ -2067,6 +2077,7 @@ process_elements (WebKitDOMNode *node,
                                                        WEBKIT_DOM_HTML_ELEMENT (quoted_node),
                                                        text_content,
                                                        NULL);
+                                               g_free (text_content);
                                        }
 
                                        /* Afterwards replace quote nodes with symbols */
@@ -2079,7 +2090,7 @@ process_elements (WebKitDOMNode *node,
 
                                        for (jj = 0; jj < length; jj++) {
                                                WebKitDOMNode *quoted_node;
-                                               const gchar *text_content;
+                                               gchar *text_content;
 
                                                quoted_node = webkit_dom_node_list_item (list, jj);
                                                text_content = webkit_dom_node_get_text_content (quoted_node);
@@ -2088,6 +2099,7 @@ process_elements (WebKitDOMNode *node,
                                                        WEBKIT_DOM_HTML_ELEMENT (quoted_node),
                                                        text_content,
                                                        NULL);
+                                               g_free (text_content);
                                        }
                                }
                        }
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index c02feef..b171314 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -3464,7 +3464,7 @@ gboolean
 element_has_id (WebKitDOMElement *element,
                 const gchar* id)
 {
-       const gchar *element_id;
+       gchar *element_id;
 
        if (!element)
                return FALSE;
@@ -3474,8 +3474,11 @@ element_has_id (WebKitDOMElement *element,
 
        element_id = webkit_dom_html_element_get_id (WEBKIT_DOM_HTML_ELEMENT (element));
 
-       if (g_ascii_strcasecmp (element_id, id) != 0)
+       if (g_ascii_strcasecmp (element_id, id) != 0) {
+               g_free (element_id);
                return FALSE;
+       }
+       g_free (element_id);
 
        return TRUE;
 }
@@ -3484,15 +3487,18 @@ gboolean
 element_has_tag (WebKitDOMElement *element,
                  const gchar* tag)
 {
-       const gchar *element_tag;
+       gchar *element_tag;
 
        if (!WEBKIT_DOM_IS_ELEMENT (element))
                return FALSE;
 
        element_tag = webkit_dom_node_get_local_name (WEBKIT_DOM_NODE (element));
 
-       if (g_ascii_strcasecmp (element_tag, tag) != 0)
+       if (g_ascii_strcasecmp (element_tag, tag) != 0) {
+               g_free (element_tag);
                return FALSE;
+       }
+       g_free (element_tag);
 
        return TRUE;
 }
@@ -3501,7 +3507,7 @@ gboolean
 element_has_class (WebKitDOMElement *element,
                 const gchar* class)
 {
-       const gchar *element_class;
+       gchar *element_class;
 
        if (!element)
                return FALSE;
@@ -3511,8 +3517,11 @@ element_has_class (WebKitDOMElement *element,
 
        element_class = webkit_dom_element_get_class_name (element);
 
-       if (g_strstr_len (element_class, -1, class))
+       if (g_strstr_len (element_class, -1, class)) {
+               g_free (element_class);
                return TRUE;
+       }
+       g_free (element_class);
 
        return FALSE;
 }
@@ -3521,7 +3530,7 @@ void
 element_add_class (WebKitDOMElement *element,
                    const gchar* class)
 {
-       const gchar *element_class;
+       gchar *element_class;
        gchar *new_class;
 
        if (!WEBKIT_DOM_IS_ELEMENT (element))
@@ -3539,6 +3548,7 @@ element_add_class (WebKitDOMElement *element,
 
        webkit_dom_element_set_class_name (element, new_class);
 
+       g_free (element_class);
        g_free (new_class);
 }
 
@@ -3548,7 +3558,7 @@ element_remove_class (WebKitDOMElement *element,
 {
        GRegex *regex;
        char *new_class;
-       const gchar *element_class;
+       gchar *element_class;
 
        if (!WEBKIT_DOM_IS_ELEMENT (element))
                return;
@@ -3560,17 +3570,21 @@ element_remove_class (WebKitDOMElement *element,
 
        if (g_strcmp0 (element_class, class) == 0) {
                webkit_dom_element_remove_attribute (element, "class");
+               g_free (element_class);
                return;
        }
 
        regex = g_regex_new (class, 0, 0, NULL);
-       if (!regex)
+       if (!regex) {
+               g_free (element_class);
                return;
+       }
 
        new_class = g_regex_replace_literal (regex, element_class, -1, 0, "", 0, NULL);
 
        webkit_dom_element_set_class_name (element, new_class);
 
+       g_free (element_class);
        g_free (new_class);
        g_regex_unref (regex);
 }



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