From 714f44f6412ecf4cfd62abd9133210f0bf937e75 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Wed, 28 Jan 2009 22:38:57 +0100 Subject: make sure strings from CSS parser are freed --- src/css.cc | 17 +++++++++++++++++ src/css.hh | 13 +++++++++---- src/cssparser.cc | 4 ++-- 3 files changed, 28 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/css.cc b/src/css.cc index a71f1ce5..30c5bc55 100644 --- a/src/css.cc +++ b/src/css.cc @@ -24,6 +24,23 @@ void CssProperty::print () { fprintf (stderr, "%s - %d\n", Css_property_info[name].symbol, value.intVal); } +CssPropertyList::~CssPropertyList () { + if (ownerOfStrings) { + for (int i = 0; i < size (); i++) { + CssProperty *p = getRef (i); + + switch (p->name) { + case CssProperty::CSS_PROPERTY_CONTENT: + case CssProperty::CSS_PROPERTY_FONT_FAMILY: + dFree (p->value.strVal); + break; + default: + break; + } + } + } +} + void CssPropertyList::set (CssProperty::Name name, CssProperty::Value value) { for (int i = 0; i < size (); i++) if (getRef (i)->name == name) { diff --git a/src/css.hh b/src/css.hh index 086e318a..0151b7f7 100644 --- a/src/css.hh +++ b/src/css.hh @@ -52,7 +52,7 @@ class CssProperty { public: typedef union { int intVal; - const char *strVal; + char *strVal; } Value; typedef enum { @@ -167,19 +167,24 @@ class CssProperty { * \brief A list of CssProperty objects. */ class CssPropertyList : public lout::misc::SimpleVector { - int refCount; + int refCount; + bool ownerOfStrings; public: - CssPropertyList() : lout::misc::SimpleVector (1) { + CssPropertyList(bool ownerOfStrings = false) : + lout::misc::SimpleVector (1) { refCount = 0; + this->ownerOfStrings = ownerOfStrings; }; CssPropertyList(const CssPropertyList &p) : lout::misc::SimpleVector (p) { refCount = 0; + ownerOfStrings = false; }; + ~CssPropertyList (); void set (CssProperty::Name name, CssProperty::Value value); - void set (CssProperty::Name name, const char *value) { + void set (CssProperty::Name name, char *value) { CssProperty::Value v; v.strVal = value; set (name, v); diff --git a/src/cssparser.cc b/src/cssparser.cc index d000c45f..03fc102c 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -1110,9 +1110,9 @@ static void Css_parse_ruleset(CssParser * parser) DEBUG_MSG(DEBUG_PARSE_LEVEL, "end of %s\n", "selectors"); - props = new CssPropertyList(); + props = new CssPropertyList(true); props->ref(); - importantProps = new CssPropertyList(); + importantProps = new CssPropertyList(true); importantProps->ref(); /* Read block. ('{' has already been read.) */ -- cgit v1.2.3