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

kdenonbeta/kdedebian/kalternatives/src



CVS commit by juanjux: 

Fixed two stupid memory leaks. Valgrind really rocks (first experience), 
it's only lacking a robotic hand to slap you in the head.


  M +24 -15    altparser.cpp   1.4
  M +15 -4     kalternatives.cpp   1.3
  M +1 -0      kalternatives.h   1.2


--- kdenonbeta/kdedebian/kalternatives/src/altparser.cpp  #1.3:1.4
@@ -111,4 +111,5 @@ bool Alternative::select()
     // And finally the slaves
     SlaveList *parslaves = parent->getSlaves();
+    parslaves->setAutoDelete(1);
     if(parslaves->count() == 0 || slaves->count() == 0) return true;
     int count = 0;
@@ -364,5 +365,5 @@ AltFilesManager::AltFilesManager(const Q
 AltFilesManager::~AltFilesManager()
 {
-    if(itemlist)delete itemlist;
+    //delete itemlist;
     /*
     Item *item;
@@ -374,4 +375,5 @@ AltFilesManager::~AltFilesManager()
     delete itemlist;
     */
+    
 }
 
@@ -406,5 +408,8 @@ bool AltFilesManager::parseAltFiles(QStr
     {
         Item *item = new Item;
-        if(*it == "." || *it == "..")continue;
+        if(*it == "." || *it == "..") {
+            delete item;
+            continue;
+        }
 
         item->setName(*it);
@@ -414,4 +419,5 @@ bool AltFilesManager::parseAltFiles(QStr
         {
             errorstr = altFile.errorString();
+            delete item;
             return false;
         }
@@ -423,4 +429,5 @@ bool AltFilesManager::parseAltFiles(QStr
             {
                 errorstr = altFile.errorString();
+                delete item;
                 return false;
             }
@@ -440,4 +447,5 @@ bool AltFilesManager::parseAltFiles(QStr
         nslaves = 0;
         SlaveList *slaves = new SlaveList;
+        slaves->setAutoDelete(1);
 
         while(line != "\n")
@@ -466,7 +474,9 @@ bool AltFilesManager::parseAltFiles(QStr
             a->setPath(tmp);
             
-            if(line=="\n")
+            if(line=="\n") {
                 //File end (with a \n)
+                delete a;
                 break;
+            }
             
             if(++index == lines.count())
@@ -499,5 +509,4 @@ bool AltFilesManager::parseAltFiles(QStr
                 }
             }
-            
             item->addAlternative(a);
         }

--- kdenonbeta/kdedebian/kalternatives/src/kalternatives.cpp  #1.2:1.3
@@ -338,7 +338,8 @@ void kalternatives::slotApplyClicked()
                 break;
         }
-        if ( getChangedList()->count() == 0 )
+        if ( countChanged() == 0 )
             apply->setEnabled(0);
     }
+    delete forChangeList;
 }
 
@@ -360,12 +361,22 @@ QPtrList<AltItemElement> *kalternatives:
         }
     }
+    // Don't forget to delete it!!
     return forChangeList;
 }
 
+int kalternatives::countChanged()
+{
+    QPtrList<AltItemElement> *fc = getChangedList();
+    int count = fc->count();
+    delete fc;
+    return count;
+}
+
+
 bool kalternatives::queryClose()
 {
   if (isRoot)
   {
-    if (getChangedList()->count() != 0)
+    if (countChanged() != 0)
     {
         if (KMessageBox::warningYesNo(this,

--- kdenonbeta/kdedebian/kalternatives/src/kalternatives.h  #1.1:1.2
@@ -133,4 +133,5 @@ class kalternatives : public KMainWindow
     void start();
     QPtrList<AltItemElement> *getChangedList();
+    int countChanged();
 
 public:




Reply to: