changeset 1746:ef983c0fe908

fix Style leaks in StyleEngine
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Sun, 17 Oct 2010 18:38:52 +0200
parents 5098b7291738
children 4e57bc05b69d
files src/styleengine.cc src/styleengine.hh
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/styleengine.cc	Sun Oct 17 18:09:22 2010 +0200
+++ b/src/styleengine.cc	Sun Oct 17 18:38:52 2010 +0200
@@ -50,6 +50,7 @@
 
    n->style = Style::create (layout, &style_attrs);
    n->wordStyle = NULL;
+   n->backgroundStyle = NULL;
    n->styleAttrProperties = NULL;
    n->nonCssProperties = NULL;
    n->inheritBackgroundColor = false;
@@ -76,6 +77,7 @@
    n->nonCssProperties = NULL;
    n->style = NULL;
    n->wordStyle = NULL;
+   n->backgroundStyle = NULL;
    n->inheritBackgroundColor = false;
 
    DoctreeNode *dn = doctree->push ();
@@ -210,6 +212,8 @@
       n->style->unref ();
    if (n->wordStyle)
       n->wordStyle->unref ();
+   if (n->backgroundStyle)
+      n->backgroundStyle->unref ();
 
    doctree->pop ();
    stack->setSize (stack->size () - 1);
@@ -659,13 +663,17 @@
  * background. This method ensures that backgroundColor is set.
  */
 Style * StyleEngine::backgroundStyle () {
-   StyleAttrs attrs = *style ();
+   if (!stack->getRef (stack->size () - 1)->backgroundStyle) {
+      StyleAttrs attrs = *style ();
 
-   for (int i = stack->size () - 1; i >= 0 && ! attrs.backgroundColor; i--)
-      attrs.backgroundColor = stack->getRef (i)->style->backgroundColor;
+      for (int i = stack->size () - 1; i >= 0 && ! attrs.backgroundColor; i--)
+         attrs.backgroundColor = stack->getRef (i)->style->backgroundColor;
 
-   assert (attrs.backgroundColor);
-   return Style::create (layout, &attrs);
+      assert (attrs.backgroundColor);
+      stack->getRef (stack->size () - 1)->backgroundStyle =
+         Style::create (layout, &attrs);
+   }
+   return stack->getRef (stack->size () - 1)->backgroundStyle;
 }
 
 /**
@@ -734,6 +742,11 @@
          n->style->unref ();
          n->style = NULL;
       }
+      if (n->wordStyle) {
+         n->wordStyle->unref ();
+         n->wordStyle = NULL;
+      }
+
       style0 (i);
    }
 }
--- a/src/styleengine.hh	Sun Oct 17 18:09:22 2010 +0200
+++ b/src/styleengine.hh	Sun Oct 17 18:38:52 2010 +0200
@@ -24,6 +24,7 @@
          CssPropertyList *nonCssProperties;
          dw::core::style::Style *style;
          dw::core::style::Style *wordStyle;
+         dw::core::style::Style *backgroundStyle;
          bool inheritBackgroundColor;
          DoctreeNode *doctreeNode;
       };