[evolution] Bug 744401 - Many WebKitDom objects leaked for every message viewed



commit 88dd1d83c9a2e95c18dc0a26602f9a738c839b99
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Feb 20 11:16:18 2015 +0100

    Bug 744401 - Many WebKitDom objects leaked for every message viewed
    
    Follow-up fix that fixes the leak of two strings introduced with
    previous fix to this bug. Also unref all the used objects from various
    lists that WebKit returns after they are used.

 addressbook/gui/widgets/eab-contact-formatter.c |    2 +-
 composer/e-composer-private.c                   |    3 +
 composer/e-msg-composer.c                       |    3 +
 e-util/e-html-editor-cell-dialog.c              |    4 +-
 e-util/e-html-editor-selection.c                |   57 +++++++++++++----
 e-util/e-html-editor-view.c                     |   75 +++++++++++++++++++----
 e-util/e-mail-signature-preview.c               |    2 +
 e-util/e-web-view.c                             |   20 +++++-
 mail/e-mail-display.c                           |    4 +
 modules/vcard-inline/e-mail-part-vcard.c        |   18 ++++--
 plugins/external-editor/external-editor.c       |    2 +
 11 files changed, 151 insertions(+), 39 deletions(-)
---
diff --git a/addressbook/gui/widgets/eab-contact-formatter.c b/addressbook/gui/widgets/eab-contact-formatter.c
index 14e0d0b..53e4f9e 100644
--- a/addressbook/gui/widgets/eab-contact-formatter.c
+++ b/addressbook/gui/widgets/eab-contact-formatter.c
@@ -1434,13 +1434,13 @@ eab_contact_formatter_bind_dom (WebKitDOMDocument *document)
 
        length = webkit_dom_node_list_get_length (nodes);
        for (ii = 0; ii < length; ii++) {
-
                WebKitDOMNode *node;
 
                node = webkit_dom_node_list_item (nodes, ii);
                webkit_dom_event_target_add_event_listener (
                        WEBKIT_DOM_EVENT_TARGET (node), "click",
                        G_CALLBACK (collapse_contacts_list), FALSE, document);
+               g_object_unref (node);
        }
 
        g_object_unref (nodes);
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 0083e79..7dcfca4 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -960,6 +960,7 @@ composer_move_caret (EMsgComposer *composer)
                } else
                        element = WEBKIT_DOM_ELEMENT (body);
 
+               g_object_unref (list);
                goto move_caret;
        }
 
@@ -1187,11 +1188,13 @@ insert:
                        }
                        /* We have to remove the div containing the span with signature */
                        remove_node (wrapper);
+                       g_object_unref (wrapper);
 
                        g_free (id);
                        break;
                }
 
+               g_object_unref (wrapper);
                g_free (id);
        }
        g_object_unref (signatures);
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 6064a69..cf3a5fd 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -3296,9 +3296,11 @@ set_signature_gui (EMsgComposer *composer)
                        uid = webkit_dom_element_get_attribute (
                                WEBKIT_DOM_ELEMENT (node), "name");
                        g_free (id);
+                       g_object_unref (node);
                        break;
                }
                g_free (id);
+               g_object_unref (node);
        }
 
        g_object_unref (nodes);
@@ -5100,6 +5102,7 @@ e_msg_composer_get_raw_message_text_without_signature (EMsgComposer *composer)
                        WEBKIT_DOM_HTML_ELEMENT (node));
                g_byte_array_append (array, (guint8 *) text, strlen (text));
                g_free (text);
+               g_object_unref (node);
        }
 
        g_object_unref (list);
diff --git a/e-util/e-html-editor-cell-dialog.c b/e-util/e-html-editor-cell-dialog.c
index 2c9680b..8dd60c7 100644
--- a/e-util/e-html-editor-cell-dialog.c
+++ b/e-util/e-html-editor-cell-dialog.c
@@ -321,7 +321,9 @@ cell_set_header_style (WebKitDOMHTMLTableCellElement *cell,
                node = webkit_dom_node_list_item (nodes, ii);
                webkit_dom_node_append_child (
                        WEBKIT_DOM_NODE (new_cell), node, NULL);
+               g_object_unref (node);
        }
+       g_object_unref (nodes);
 
        /* Insert new_cell before cell and remove cell */
        webkit_dom_node_insert_before (
@@ -336,8 +338,6 @@ cell_set_header_style (WebKitDOMHTMLTableCellElement *cell,
 
        dialog->priv->cell = new_cell;
 
-       g_object_unref (nodes);
-
        g_free (tagname);
 }
 
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 73c823b..286cbfe 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -1469,6 +1469,7 @@ e_html_editor_selection_set_alignment (EHTMLEditorSelection *selection,
 
                                        after_selection_end = webkit_dom_node_contains (
                                                item, WEBKIT_DOM_NODE (selection_end_marker));
+                                       g_object_unref (item);
                                        if (after_selection_end)
                                                break;
                                }
@@ -1775,8 +1776,11 @@ remove_wrapping_from_element (WebKitDOMElement *element)
        list = webkit_dom_element_query_selector_all (
                element, "br.-x-evo-wrap-br", NULL);
        length = webkit_dom_node_list_get_length (list);
-       for (ii = 0; ii < length; ii++)
-               remove_node (webkit_dom_node_list_item (list, ii));
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+               remove_node (node);
+               g_object_unref (node);
+       }
 
        webkit_dom_node_normalize (WEBKIT_DOM_NODE (element));
 
@@ -1792,8 +1796,11 @@ remove_quoting_from_element (WebKitDOMElement *element)
        list = webkit_dom_element_query_selector_all (
                element, "span.-x-evo-quoted", NULL);
        length = webkit_dom_node_list_get_length (list);
-       for (ii = 0; ii < length; ii++)
-               remove_node (webkit_dom_node_list_item (list, ii));
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+               remove_node (node);
+               g_object_unref (node);
+       }
        g_object_unref (list);
 
        list = webkit_dom_element_query_selector_all (
@@ -1811,14 +1818,18 @@ remove_quoting_from_element (WebKitDOMElement *element)
                                NULL);
 
                remove_node (node);
+               g_object_unref (node);
        }
        g_object_unref (list);
 
        list = webkit_dom_element_query_selector_all (
                element, "br.-x-evo-temp-br", NULL);
        length = webkit_dom_node_list_get_length (list);
-       for (ii = 0; ii < length; ii++)
-               remove_node (webkit_dom_node_list_item (list, ii));
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+               remove_node (node);
+               g_object_unref (node);
+       }
        g_object_unref (list);
 
        webkit_dom_node_normalize (WEBKIT_DOM_NODE (element));
@@ -3073,8 +3084,10 @@ e_html_editor_selection_indent (EHTMLEditorSelection *selection)
                                after_selection_start = webkit_dom_node_contains (
                                        block_to_process,
                                        WEBKIT_DOM_NODE (selection_start_marker));
-                               if (!after_selection_start)
+                               if (!after_selection_start) {
+                                       g_object_unref (block_to_process);
                                        continue;
+                               }
                        }
 
                        level = get_indentation_level (
@@ -3082,13 +3095,18 @@ e_html_editor_selection_indent (EHTMLEditorSelection *selection)
 
                        final_width = word_wrap_length - SPACES_PER_INDENTATION * (level + 1);
                        if (final_width < MINIMAL_PARAGRAPH_WIDTH &&
-                           !is_in_html_mode (selection))
+                           !is_in_html_mode (selection)) {
+                               g_object_unref (block_to_process);
                                continue;
+                       }
 
                        indent_block (selection, document, block_to_process, final_width);
 
-                       if (after_selection_end)
+                       if (after_selection_end) {
+                               g_object_unref (block_to_process);
                                break;
+                       }
+                       g_object_unref (block_to_process);
                }
 
  next:
@@ -3389,14 +3407,20 @@ e_html_editor_selection_unindent (EHTMLEditorSelection *selection)
                                after_selection_start = webkit_dom_node_contains (
                                        block_to_process,
                                        WEBKIT_DOM_NODE (selection_start_marker));
-                               if (!after_selection_start)
+                               if (!after_selection_start) {
+                                       g_object_unref (block_to_process);
                                        continue;
+                               }
                        }
 
                        unindent_block (selection, document, block_to_process);
 
-                       if (after_selection_end)
+                       if (after_selection_end) {
+                               g_object_unref (block_to_process);
                                break;
+                       }
+
+                       g_object_unref (block_to_process);
                }
  next:
                g_object_unref (list);
@@ -5254,13 +5278,14 @@ wrap_lines (EHTMLEditorSelection *selection,
        WebKitDOMNode *paragraph_clone;
        WebKitDOMDocumentFragment *fragment;
        WebKitDOMElement *element;
-       WebKitDOMNodeList *wrap_br;
        gint len, ii, br_count;
        gulong length_left;
        glong paragraph_char_count;
        gchar *text_content;
 
        if (selection) {
+               WebKitDOMNodeList *wrap_br;
+
                paragraph_char_count = g_utf8_strlen (
                        e_html_editor_selection_get_string (selection), -1);
 
@@ -5276,8 +5301,11 @@ wrap_lines (EHTMLEditorSelection *selection,
                        NULL);
                br_count = webkit_dom_node_list_get_length (wrap_br);
                /* And remove them */
-               for (ii = 0; ii < br_count; ii++)
-                       remove_node (webkit_dom_node_list_item (wrap_br, ii));
+               for (ii = 0; ii < br_count; ii++) {
+                       WebKitDOMNode *node = webkit_dom_node_list_item (wrap_br, ii);
+                       remove_node (node);
+                       g_object_unref (node);
+               }
                g_object_unref (wrap_br);
        } else {
                if (!webkit_dom_node_has_child_nodes (paragraph))
@@ -5900,6 +5928,7 @@ e_html_editor_selection_wrap_paragraphs_in_document (EHTMLEditorSelection *selec
                                WEBKIT_DOM_ELEMENT (node),
                                selection->priv->word_wrap_length - quote);
                }
+               g_object_unref (node);
        }
        g_object_unref (list);
 }
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index fee7a7a..c6eeafe 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -633,6 +633,7 @@ quote_plain_text_element_after_wrapping (WebKitDOMDocument *document,
                        webkit_dom_node_clone_node (quoted_node, TRUE),
                        webkit_dom_node_get_next_sibling (br),
                        NULL);
+               g_object_unref (br);
        }
 
        g_object_unref (list);
@@ -943,6 +944,7 @@ change_cid_images_src_to_base64 (EHTMLEditorView *view)
                WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
 
                set_base64_to_element_attribute (view, WEBKIT_DOM_ELEMENT (node), "src");
+               g_object_unref (node);
        }
        g_object_unref (list);
 
@@ -969,12 +971,14 @@ change_cid_images_src_to_base64 (EHTMLEditorView *view)
 
                                set_base64_to_element_attribute (
                                        view, WEBKIT_DOM_ELEMENT (node), attribute_ns);
+                               g_object_unref (node);
                        }
 
                        g_object_unref (list);
                        g_free (attribute_ns);
                        g_free (selector);
                }
+               g_object_unref (node);
                g_free (name);
        }
        g_object_unref (attributes);
@@ -987,6 +991,7 @@ change_cid_images_src_to_base64 (EHTMLEditorView *view)
 
                set_base64_to_element_attribute (
                        view, WEBKIT_DOM_ELEMENT (node), "background");
+               g_object_unref (node);
        }
        g_object_unref (list);
        g_hash_table_remove_all (view->priv->inline_images);
@@ -1046,6 +1051,7 @@ move_elements_to_body (WebKitDOMDocument *document)
                }
 
                remove_node (node);
+               g_object_unref (node);
        }
        g_object_unref (list);
 
@@ -1069,6 +1075,7 @@ move_elements_to_body (WebKitDOMDocument *document)
                        NULL);
 
                remove_node (node);
+               g_object_unref (node);
        }
        g_object_unref (list);
 }
@@ -1088,6 +1095,7 @@ repair_gmail_blockquotes (WebKitDOMDocument *document)
                webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (node), "class");
                webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (node), "style");
                webkit_dom_element_set_attribute (WEBKIT_DOM_ELEMENT (node), "type", "cite", NULL);
+               g_object_unref (node);
        }
        g_object_unref (list);
 }
@@ -1817,6 +1825,7 @@ mark_node_as_paragraph_after_ending_list (EHTMLEditorSelection *selection,
 
                e_html_editor_selection_set_paragraph_style (
                        selection, WEBKIT_DOM_ELEMENT (node), -1, 0, "");
+               g_object_unref (node);
        }
        g_object_unref (list);
 }
@@ -2176,8 +2185,11 @@ remove_empty_blocks (WebKitDOMDocument *document)
                document, "blockquote[type=cite] > :empty", NULL);
 
        length = webkit_dom_node_list_get_length (list);
-       for  (ii = 0; ii < length; ii++)
-               remove_node (webkit_dom_node_list_item (list, ii));
+       for  (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+               remove_node (node);
+               g_object_unref (node);
+       }
 
        g_object_unref (list);
 }
@@ -4025,8 +4037,12 @@ e_html_editor_view_quote_plain_text_element (EHTMLEditorView *view,
        list = webkit_dom_element_query_selector_all (
                WEBKIT_DOM_ELEMENT (element_clone), "span.-x-evo-quoted", NULL);
        length = webkit_dom_node_list_get_length (list);
-       for  (ii = 0; ii < length; ii++)
-               remove_node (webkit_dom_node_list_item (list, ii));
+       for  (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+               remove_node (node);
+               g_object_unref (node);
+       }
+       g_object_unref (list);
 
        webkit_dom_node_normalize (element_clone);
        quote_plain_text_recursive (
@@ -4045,7 +4061,6 @@ e_html_editor_view_quote_plain_text_element (EHTMLEditorView *view,
                WEBKIT_DOM_NODE (element),
                NULL);
 
-       g_object_unref (list);
        return WEBKIT_DOM_ELEMENT (element_clone);
 }
 
@@ -4101,6 +4116,7 @@ e_html_editor_view_quote_plain_text (EHTMLEditorView *view)
                        if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (child))
                                remove_node (child);
                }
+               g_object_unref (blockquote);
        }
        g_object_unref (list);
 
@@ -4120,6 +4136,7 @@ e_html_editor_view_quote_plain_text (EHTMLEditorView *view)
                webkit_dom_element_set_attribute (
                        WEBKIT_DOM_ELEMENT (body_clone), name, value, NULL);
 
+               g_object_unref (node);
                g_free (name);
                g_free (value);
        }
@@ -4164,6 +4181,7 @@ e_html_editor_view_dequote_plain_text (EHTMLEditorView *view)
                        element_remove_class (element, "-x-evo-plaintext-quoted");
                        remove_quoting_from_element (element);
                }
+               g_object_unref (element);
        }
        g_object_unref (paragraphs);
 }
@@ -4778,6 +4796,7 @@ quote_plain_text_elements_after_wrapping_in_document (WebKitDOMDocument *documen
                citation_level = get_citation_level (child, TRUE);
                quote_plain_text_element_after_wrapping (
                        document, WEBKIT_DOM_ELEMENT (child), citation_level);
+               g_object_unref (child);
        }
        g_object_unref (list);
 }
@@ -4800,6 +4819,7 @@ clear_attributes (WebKitDOMDocument *document)
 
                webkit_dom_element_remove_attribute_node (
                        document_element, WEBKIT_DOM_ATTR (node), NULL);
+               g_object_unref (node);
        }
        g_object_unref (attributes);
 
@@ -4826,6 +4846,7 @@ clear_attributes (WebKitDOMDocument *document)
                                NULL);
 
                g_free (name);
+               g_object_unref (node);
        }
        g_object_unref (attributes);
 }
@@ -4902,8 +4923,11 @@ html_editor_convert_view_content (EHTMLEditorView *view,
        list = webkit_dom_document_query_selector_all (
                document, ".-x-evo-paragraph", NULL);
        length = webkit_dom_node_list_get_length (list);
-       for (ii = 0; ii < length; ii++)
-               remove_node (webkit_dom_node_list_item (list, ii));
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+               remove_node (node);
+               g_object_unref (node);
+       }
        g_object_unref (list);
 
        /* Insert the paragraph where the caret will be. */
@@ -4974,6 +4998,7 @@ html_editor_convert_view_content (EHTMLEditorView *view,
                        NULL);
 
                remove_node (node);
+               g_object_unref (node);
        }
        g_object_unref (list);
 
@@ -4994,6 +5019,7 @@ html_editor_convert_view_content (EHTMLEditorView *view,
                }
 
                remove_node (node);
+               g_object_unref (node);
        }
        g_object_unref (list);
 
@@ -5741,6 +5767,7 @@ process_blockquote (WebKitDOMElement *blockquote)
                        WEBKIT_DOM_HTML_ELEMENT (quoted_node), text_content, NULL);
 
                g_free (text_content);
+               g_object_unref (quoted_node);
        }
        g_object_unref (list);
 
@@ -5758,6 +5785,7 @@ process_blockquote (WebKitDOMElement *blockquote)
                        WEBKIT_DOM_HTML_ELEMENT (quoted_node), text_content, NULL);
 
                g_free (text_content);
+               g_object_unref (quoted_node);
        }
        g_object_unref (list);
 
@@ -6196,6 +6224,7 @@ process_elements (EHTMLEditorView *view,
 
                                g_free (name);
                                g_free (value);
+                               g_object_unref (node);
                        }
                        g_string_append (buffer, ">");
                        g_object_unref (attributes);
@@ -6602,6 +6631,7 @@ process_elements (EHTMLEditorView *view,
                if (webkit_dom_node_has_child_nodes (child) && !skip_node)
                        process_elements (
                                view, child, to_html, changing_mode, to_plain_text, buffer);
+               g_object_unref (child);
        }
 
        if (to_plain_text && (
@@ -6650,8 +6680,11 @@ remove_wrapping_from_view (EHTMLEditorView *view)
        list = webkit_dom_document_query_selector_all (document, "br.-x-evo-wrap-br", NULL);
 
        length = webkit_dom_node_list_get_length (list);
-       for (ii = 0; ii < length; ii++)
-               remove_node (webkit_dom_node_list_item (list, ii));
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+               remove_node (node);
+               g_object_unref (node);
+       }
 
        g_object_unref (list);
 }
@@ -6680,6 +6713,7 @@ remove_background_images_in_document (WebKitDOMDocument *document)
                        webkit_dom_node_list_item (elements, ii));
 
                remove_image_attributes_from_element (element);
+               g_object_unref (element);
        }
 
        g_object_unref (elements);
@@ -6696,8 +6730,11 @@ remove_images_in_element (EHTMLEditorView *view,
                element, "img:not(.-x-evo-smiley-img)", NULL);
 
        length = webkit_dom_node_list_get_length (images);
-       for (ii = 0; ii < length; ii++)
-               remove_node (webkit_dom_node_list_item (images, ii));
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (images, ii);
+               remove_node (node);
+               g_object_unref (node);
+       }
 
        g_object_unref (images);
 }
@@ -6747,6 +6784,7 @@ toggle_smileys (EHTMLEditorView *view)
                        element_add_class (parent, "-x-evo-resizable-wrapper");
                else
                        element_remove_class (parent, "-x-evo-resizable-wrapper");
+               g_object_unref (img);
        }
 
        g_object_unref (smileys);
@@ -6817,6 +6855,7 @@ toggle_paragraphs_style_in_element (EHTMLEditorView *view,
                                g_free (style);
                        }
                }
+               g_object_unref (node);
        }
        g_object_unref (paragraphs);
 }
@@ -7065,6 +7104,7 @@ process_content_for_plain_text (EHTMLEditorView *view)
 
                                webkit_dom_element_remove_attribute (
                                        WEBKIT_DOM_ELEMENT (paragraph), "id");
+                               g_object_unref (paragraph);
                        }
                        g_object_unref (paragraphs);
 
@@ -7106,6 +7146,7 @@ process_content_for_plain_text (EHTMLEditorView *view)
                        e_html_editor_selection_wrap_paragraph (
                                selection, WEBKIT_DOM_ELEMENT (paragraph));
                }
+               g_object_unref (paragraph);
        }
        g_object_unref (paragraphs);
 
@@ -7120,6 +7161,7 @@ process_content_for_plain_text (EHTMLEditorView *view)
                WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node);
 
                remove_node (node);
+               g_object_unref (node);
                webkit_dom_node_normalize (parent);
        }
        g_object_unref (paragraphs);
@@ -7430,6 +7472,7 @@ wrap_paragraphs_in_quoted_content (EHTMLEditorSelection *selection,
 
                e_html_editor_selection_wrap_paragraph (
                        selection, WEBKIT_DOM_ELEMENT (paragraph));
+               g_object_unref (paragraph);
        }
        g_object_unref (paragraphs);
 }
@@ -7573,7 +7616,9 @@ html_editor_view_drag_end_cb (EHTMLEditorView *view,
                        NULL);
 
                webkit_dom_node_append_child (WEBKIT_DOM_NODE (element), node, NULL);
+               g_object_unref (node);
        }
+       g_object_unref (list);
 
        /* When the image is moved the new selection is created after after it, so
         * lets collapse the selection to have the caret right after the image. */
@@ -8020,6 +8065,7 @@ html_editor_view_get_parts_for_inline_images (EHTMLEditorView *view,
                webkit_dom_element_set_attribute (
                        WEBKIT_DOM_ELEMENT (node), "src", cid, NULL);
                g_free (cid);
+               g_object_unref (node);
        }
        g_object_unref (list);
 
@@ -8028,8 +8074,10 @@ html_editor_view_get_parts_for_inline_images (EHTMLEditorView *view,
                document, "[data-inline][background]", NULL);
 
        length = webkit_dom_node_list_get_length (list);
-       if (length == 0)
+       if (length == 0) {
+               g_object_unref (list);
                return parts;
+       }
        if (!*inline_images)
                *inline_images = g_hash_table_new_full (
                        g_str_hash, g_str_equal, g_free, g_free);
@@ -8060,6 +8108,7 @@ html_editor_view_get_parts_for_inline_images (EHTMLEditorView *view,
                        } else
                                g_free (src);
                }
+               g_object_unref (node);
                g_free (cid);
        }
 
@@ -8138,6 +8187,7 @@ restore_images (gchar *key,
                        webkit_dom_node_list_item (list, ii));
 
                webkit_dom_element_set_attribute (element, "background", key, NULL);
+               g_object_unref (element);
        }
        g_free (selector);
        g_object_unref (list);
@@ -8150,6 +8200,7 @@ restore_images (gchar *key,
                        webkit_dom_node_list_item (list, ii));
 
                webkit_dom_element_set_attribute (element, "src", key, NULL);
+               g_object_unref (element);
        }
        g_free (selector);
        g_object_unref (list);
diff --git a/e-util/e-mail-signature-preview.c b/e-util/e-mail-signature-preview.c
index f125c8b..eb67a3d 100644
--- a/e-util/e-mail-signature-preview.c
+++ b/e-util/e-mail-signature-preview.c
@@ -79,6 +79,7 @@ replace_local_image_links (WebKitDOMDocument *document)
                webkit_dom_html_image_element_set_src (img, new_src);
                g_free (new_src);
                g_free (src);
+               g_object_unref (img);
        }
        g_object_unref (list);
 
@@ -96,6 +97,7 @@ replace_local_image_links (WebKitDOMDocument *document)
 
                if (content_document && WEBKIT_DOM_IS_DOCUMENT (content_document))
                        replace_local_image_links (content_document);
+               g_object_unref (iframe);
        }
        g_object_unref (list);
 }
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index 6d2f9c2..13a85e8 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -2534,8 +2534,11 @@ web_view_get_frame_selection_html (WebKitDOMElement *iframe)
                text = web_view_get_frame_selection_html (
                        WEBKIT_DOM_ELEMENT (node));
 
-               if (text != NULL)
+               g_object_unref (node);
+               if (text != NULL) {
+                       g_object_unref (frames);
                        return text;
+               }
        }
        g_object_unref (frames);
 
@@ -2567,8 +2570,11 @@ e_web_view_get_selection_html (EWebView *web_view)
                text = web_view_get_frame_selection_html (
                        WEBKIT_DOM_ELEMENT (node));
 
-               if (text != NULL)
+               g_object_unref (node);
+               if (text != NULL) {
+                       g_object_unref (frames);
                        return text;
+               }
        }
        g_object_unref (frames);
 
@@ -3377,7 +3383,7 @@ add_css_rule_into_style_sheet (WebKitDOMDocument *document,
                rule = webkit_dom_css_rule_list_item (rules_list, ii);
 
                if (!WEBKIT_DOM_IS_CSS_RULE (rule))
-                       continue;
+                       goto next;
 
                rule_text = webkit_dom_css_rule_get_css_text (rule);
 
@@ -3385,7 +3391,7 @@ add_css_rule_into_style_sheet (WebKitDOMDocument *document,
                selector_end = g_strstr_len (rule_text, -1, " {");
                if (!selector_end) {
                        g_free (rule_text);
-                       continue;
+                       goto next;
                }
 
                rule_selector =
@@ -3400,11 +3406,16 @@ add_css_rule_into_style_sheet (WebKitDOMDocument *document,
                                WEBKIT_DOM_CSS_STYLE_SHEET (sheet),
                                ii, NULL);
                        length--;
+                       g_free (rule_selector);
+                       g_free (rule_text);
+                       g_object_unref (rule);
                        break;
                }
 
                g_free (rule_selector);
                g_free (rule_text);
+ next:
+               g_object_unref (rule);
        }
 
        g_object_unref (rules_list);
@@ -3447,6 +3458,7 @@ add_css_rule_into_style_sheet_recursive (WebKitDOMDocument *document,
                        style_sheet_id,
                        selector,
                        style);
+               g_object_unref (node);
        }
        g_object_unref (frames);
 }
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index dc5e0cb..c168cc9 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -341,6 +341,7 @@ find_element_by_id (WebKitDOMDocument *document,
 
                element = find_element_by_id (frame_doc, id);
 
+               g_object_unref (iframe);
                if (element != NULL)
                        goto out;
        }
@@ -976,6 +977,7 @@ setup_image_click_event_listeners_on_document (WebKitDOMDocument *document,
                        WEBKIT_DOM_EVENT_TARGET (button), "click",
                        G_CALLBACK (toggle_address_visibility), FALSE,
                        NULL);
+               g_object_unref (button);
        }
        g_object_unref (list);
 }
@@ -2164,6 +2166,7 @@ mail_display_get_frame_selection_text (WebKitDOMElement *iframe)
                text = mail_display_get_frame_selection_text (
                        WEBKIT_DOM_ELEMENT (node));
 
+               g_object_unref (node);
                if (text != NULL) {
                        g_object_unref (frames);
                        return text;
@@ -2200,6 +2203,7 @@ e_mail_display_get_selection_plain_text (EMailDisplay *display)
                text = mail_display_get_frame_selection_text (
                        WEBKIT_DOM_ELEMENT (node));
 
+               g_object_unref (node);
                if (text != NULL) {
                        g_object_unref (frames);
                        return text;
diff --git a/modules/vcard-inline/e-mail-part-vcard.c b/modules/vcard-inline/e-mail-part-vcard.c
index f97d47b..f164ab6 100644
--- a/modules/vcard-inline/e-mail-part-vcard.c
+++ b/modules/vcard-inline/e-mail-part-vcard.c
@@ -262,31 +262,37 @@ mail_part_vcard_bind_dom_element (EMailPart *part,
        /* IFRAME */
        list = webkit_dom_element_get_elements_by_tag_name (
                element, "iframe");
-       if (webkit_dom_node_list_get_length (list) != 1)
+       if (webkit_dom_node_list_get_length (list) != 1) {
+               g_object_unref (list);
                return;
+       }
        iframe = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, 0));
        g_clear_object (&vcard_part->iframe);
-       vcard_part->iframe = g_object_ref (iframe);
+       vcard_part->iframe = iframe;
        g_object_unref (list);
 
        /* TOGGLE DISPLAY MODE BUTTON */
        list = webkit_dom_element_get_elements_by_class_name (
                element, "org-gnome-vcard-display-mode-button");
-       if (webkit_dom_node_list_get_length (list) != 1)
+       if (webkit_dom_node_list_get_length (list) != 1) {
+               g_object_unref (list);
                return;
+       }
        toggle_button = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, 0));
        g_clear_object (&vcard_part->toggle_button);
-       vcard_part->toggle_button = g_object_ref (toggle_button);
+       vcard_part->toggle_button = toggle_button;
        g_object_unref (list);
 
        /* SAVE TO ADDRESSBOOK BUTTON */
        list = webkit_dom_element_get_elements_by_class_name (
                element, "org-gnome-vcard-save-button");
-       if (webkit_dom_node_list_get_length (list) != 1)
+       if (webkit_dom_node_list_get_length (list) != 1) {
+               g_object_unref (list);
                return;
+       }
        save_button = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, 0));
        g_clear_object (&vcard_part->save_button);
-       vcard_part->save_button = g_object_ref (save_button);
+       vcard_part->save_button = save_button;
        g_object_unref (list);
 
        webkit_dom_event_target_add_event_listener (
diff --git a/plugins/external-editor/external-editor.c b/plugins/external-editor/external-editor.c
index 924ae23..d41ae29 100644
--- a/plugins/external-editor/external-editor.c
+++ b/plugins/external-editor/external-editor.c
@@ -286,12 +286,14 @@ get_caret_position (EHTMLEditorView *view)
                if (webkit_dom_node_is_same_node (
                        node, webkit_dom_dom_selection_get_anchor_node (selection))) {
 
+                       g_object_unref (node);
                        break;
                } else if (WEBKIT_DOM_IS_TEXT (node)) {
                        gchar *text = webkit_dom_node_get_text_content (node);
                        range_count += strlen (text);
                        g_free (text);
                }
+               g_object_unref (node);
        }
 
        g_object_unref (nodes);


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