[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    patch: refcounting fixes
From:       Dirk Mueller <mueller () kde ! org>
Date:       2001-09-26 17:47:39
[Download RAW message or body]

Hi, 

patch below cleans up the refcounting bugs in CSS*RuleImpl. I'm not sure 
which testsite the patch was supposed to fix so I cannot test if I messed 
something up, but by code reviewal this is the right way imho. 

please have a look. 


Dirk

["refcounting.patch" (text/plain)]

Index: css/css_ruleimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/css/css_ruleimpl.cpp,v
retrieving revision 1.22
diff -u -3 -r1.22 css_ruleimpl.cpp
--- css/css_ruleimpl.cpp	2001/09/26 13:02:05	1.22
+++ css/css_ruleimpl.cpp	2001/09/26 17:46:34
@@ -196,10 +196,8 @@
 
 CSSMediaRuleImpl::~CSSMediaRuleImpl()
 {
-    if( m_lstMedia )
-        m_lstMedia->deref();
-    if( m_lstCSSRules )
-        m_lstCSSRules->deref();
+    m_lstMedia->deref();
+    m_lstCSSRules->deref();
 }
 
 MediaListImpl *CSSMediaRuleImpl::media() const
@@ -217,14 +215,11 @@
 {
     const QChar *curP = rule.unicode();
     CSSRuleImpl *newRule = parseRule( curP, curP + rule.length() );
-                                   
+
     if( newRule )
-    {
-        newRule->ref();
         return m_lstCSSRules->insertRule( newRule, index );
-    }
-    else
-        return 0;
+
+    return 0;
 }
 
 void CSSMediaRuleImpl::deleteRule( unsigned long index )
@@ -342,6 +337,13 @@
 {
 }
 
+CSSRuleListImpl::~CSSRuleListImpl()
+{
+    CSSRuleImpl* rule;
+    while ( ( rule = m_lstCSSRules.take( 0 ) ) )
+        rule->deref();
+}
+
 unsigned long CSSRuleListImpl::length() const
 {
     return m_lstCSSRules.count();
@@ -354,22 +356,20 @@
 
 void CSSRuleListImpl::deleteRule ( unsigned long index )
 {
-    CSSRuleImpl *rule = m_lstCSSRules.at( index );
+    CSSRuleImpl *rule = m_lstCSSRules.take( index );
     if( rule )
-    {
-        m_lstCSSRules.remove( index );
         rule->deref();
-    }
 }
 
 unsigned long CSSRuleListImpl::insertRule( CSSRuleImpl *rule,
                                            unsigned long index )
 {
-    if( m_lstCSSRules.insert( index, rule ) )
+    if( rule && m_lstCSSRules.insert( index, rule ) ) {
+        rule->ref();
         return index;
-    else
-        rule->deref();    // insertion failed
-        
+    }
+
+    // ### return count()+1 here ?
     return 0;
 }
 
Index: css/css_ruleimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/css/css_ruleimpl.h,v
retrieving revision 1.12
diff -u -3 -r1.12 css_ruleimpl.h
--- css/css_ruleimpl.h	2001/09/26 09:09:00	1.12
+++ css/css_ruleimpl.h	2001/09/26 17:46:34
@@ -140,7 +140,7 @@
     virtual bool isMediaRule() { return true; }
 protected:
     MediaListImpl *m_lstMedia;
-	CSSRuleListImpl *m_lstCSSRules;
+    CSSRuleListImpl *m_lstCSSRules;
 };
 
 
@@ -193,38 +193,32 @@
 };
 
 
-
 class CSSUnknownRuleImpl : public CSSRuleImpl
 {
 public:
     CSSUnknownRuleImpl(StyleBaseImpl *parent);
 
     ~CSSUnknownRuleImpl();
-
-     virtual bool isUnknownRule() { return true; }
+    
+    virtual bool isUnknownRule() { return true; }
 };
 
+
 class CSSRuleListImpl : public DomShared
 {
 public:
     CSSRuleListImpl();
+    ~CSSRuleListImpl();
 
     unsigned long length() const;
     CSSRuleImpl *item ( unsigned long index );
-   
-    /**
-     * Internal API, _NOT_ to be exposed outside! (Used by CSSMediaRuleImpl)
-     */
+
+    /* not part of the DOM */
     unsigned long insertRule ( CSSRuleImpl *rule, unsigned long index );
     void deleteRule ( unsigned long index );
     
 protected:
-#if QT_VERSION < 300
     QList<CSSRuleImpl> m_lstCSSRules;
-#else
-    QPtrList<CSSRuleImpl> m_lstCSSRules;
-#endif
-
 };
 
 }; // namespace


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic