[evolution] EMailDisplay - Fix more leaks of WebKit objects



commit e3106bf38655d941254bece4e5dc8d89371bda29
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Feb 27 09:00:02 2015 +0100

    EMailDisplay - Fix more leaks of WebKit objects

 mail/e-mail-display.c |   57 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 37 insertions(+), 20 deletions(-)
---
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 607278a..093e593 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -467,6 +467,7 @@ attachment_button_expanded (GObject *object,
        css = webkit_dom_element_get_style (element);
        webkit_dom_css_style_declaration_set_property (
                css, "display", expanded ? "block" : "none", "", NULL);
+       g_object_unref (css);
 }
 
 static void
@@ -733,8 +734,8 @@ toggle_headers_visibility (WebKitDOMElement *button,
                            WebKitWebView *web_view)
 {
        WebKitDOMDocument *document;
-       WebKitDOMElement *short_headers, *full_headers;
-       WebKitDOMCSSStyleDeclaration *css_short, *css_full;
+       WebKitDOMElement *short_headers = NULL, *full_headers = NULL;
+       WebKitDOMCSSStyleDeclaration *css_short = NULL, *css_full = NULL;
        gboolean expanded;
        const gchar *path;
        gchar *css_value;
@@ -751,7 +752,7 @@ toggle_headers_visibility (WebKitDOMElement *button,
        full_headers = webkit_dom_document_get_element_by_id (
                document, "__evo-full-headers");
        if (full_headers == NULL)
-               return;
+               goto clean;
 
        css_full = webkit_dom_element_get_style (full_headers);
        css_value = webkit_dom_css_style_declaration_get_property_value (
@@ -778,40 +779,47 @@ toggle_headers_visibility (WebKitDOMElement *button,
                E_MAIL_DISPLAY (web_view), expanded);
 
        d (printf ("Headers %s!\n", expanded ? "collapsed" : "expanded"));
+ clean:
+       g_clear_object (&short_headers);
+       g_clear_object (&css_short);
+       g_clear_object (&full_headers);
+       g_clear_object (&css_full);
 }
 
 static void
 toggle_address_visibility (WebKitDOMElement *button,
                            WebKitDOMEvent *event)
 {
-       WebKitDOMElement *full_addr, *ellipsis;
-       WebKitDOMElement *parent;
-       WebKitDOMCSSStyleDeclaration *css_full, *css_ellipsis;
+       WebKitDOMElement *full_addr = NULL, *ellipsis = NULL;
+       WebKitDOMElement *parent = NULL, *bold = NULL;
+       WebKitDOMCSSStyleDeclaration *css_full = NULL, *css_ellipsis = NULL;
        const gchar *path;
+       gchar *property_value;
        gboolean expanded;
 
        /* <b> element */
-       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (button));
+       bold = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (button));
        /* <td> element */
-       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (parent));
+       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (bold));
+       g_object_unref (bold);
 
        full_addr = webkit_dom_element_query_selector (parent, "#__evo-moreaddr", NULL);
 
        if (!full_addr)
-               return;
+               goto clean;
 
        css_full = webkit_dom_element_get_style (full_addr);
 
        ellipsis = webkit_dom_element_query_selector (parent, "#__evo-moreaddr-ellipsis", NULL);
 
        if (!ellipsis)
-               return;
+               goto clean;
 
        css_ellipsis = webkit_dom_element_get_style (ellipsis);
 
-       expanded = (g_strcmp0 (
-               webkit_dom_css_style_declaration_get_property_value (
-               css_full, "display"), "inline") == 0);
+       property_value = webkit_dom_css_style_declaration_get_property_value (css_full, "display");
+       expanded = g_strcmp0 (property_value, "inline") == 0;
+       g_free (property_value);
 
        webkit_dom_css_style_declaration_set_property (
                css_full, "display", (expanded ? "none" : "inline"), "", NULL);
@@ -824,14 +832,23 @@ toggle_address_visibility (WebKitDOMElement *button,
                path = "evo-file://" EVOLUTION_IMAGESDIR "/minus.png";
 
        if (!WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT (button)) {
-               button = webkit_dom_element_query_selector (parent, "#__evo-moreaddr-img", NULL);
-
-               if (!button)
-                       return;
-       }
+               WebKitDOMElement *element;
 
-       webkit_dom_html_image_element_set_src (
-               WEBKIT_DOM_HTML_IMAGE_ELEMENT (button), path);
+               element = webkit_dom_element_query_selector (parent, "#__evo-moreaddr-img", NULL);
+               if (!element)
+                       goto clean;
+
+               webkit_dom_html_image_element_set_src (WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), path);
+
+               g_object_unref (element);
+       } else
+               webkit_dom_html_image_element_set_src (WEBKIT_DOM_HTML_IMAGE_ELEMENT (button), path);
+ clean:
+       g_clear_object (&css_full);
+       g_clear_object (&css_ellipsis);
+       g_clear_object (&full_addr);
+       g_clear_object (&ellipsis);
+       g_clear_object (&parent);
 }
 
 static void


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