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

List:       kde-commits
Subject:    [libqapt] src: - Fix a memleak if a client calls setCompressEvents(true) multiple times before setCo
From:       Jonathan Thomas <echidnaman () kubuntu ! org>
Date:       2014-02-19 17:24:34
Message-ID: E1WGAss-0001OL-6K () scm ! kde ! org
[Download RAW message or body]

Git commit 5a847c39a2cb341d1395eaba4313e628452bc1ac by Jonathan Thomas.
Committed on 19/02/2014 at 17:22.
Pushed by jmthomas into branch 'master'.

- Fix a memleak if a client calls setCompressEvents(true) multiple times before setCompressEvents(false)
- Fix the ActionGroup pointer not being deleted if events are compressed during Backend destruction
- Minor cleanups related to setCompressEvents/areEventsCompressed

M  +9    -5    src/backend.cpp

http://commits.kde.org/libqapt/5a847c39a2cb341d1395eaba4313e628452bc1ac

diff --git a/src/backend.cpp b/src/backend.cpp
index 7aad222..cb08b13 100644
--- a/src/backend.cpp
+++ b/src/backend.cpp
@@ -60,7 +60,7 @@ public:
         , xapianDatabase(nullptr)
         , xapianIndexExists(false)
         , config(nullptr)
-        , compressEvents(false)
+        , actionGroup(nullptr)
         , frontendCaps(QApt::NoCaps)
     {
     }
@@ -71,6 +71,7 @@ public:
         delete records;
         delete config;
         delete xapianDatabase;
+        delete actionGroup;
     }
     // Caches
     // The canonical list of all unique, non-virutal package objects
@@ -844,7 +845,7 @@ bool Backend::areEventsCompressed() const
 {
     Q_D(const Backend);
 
-    return d->compressEvents;
+    return d->actionGroup != nullptr;
 }
 
 void Backend::undo()
@@ -993,12 +994,15 @@ void Backend::setCompressEvents(bool enabled)
     Q_D(Backend);
 
     if (enabled) {
+         // Ignore if already compressed
+        if (d->actionGroup != nullptr)
+            return;
+
+        // Presence of an ActionGroup compresses marking events over its lifetime
         d->actionGroup = new pkgDepCache::ActionGroup(*d->cache->depCache());
-        d->compressEvents = true;
     } else {
         delete d->actionGroup;
-        d->actionGroup = 0;
-        d->compressEvents = false;
+        d->actionGroup = nullptr;
         emit packageChanged();
     }
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

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