summaryrefslogtreecommitdiff
path: root/apt-pkg/cachefile.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2018-09-24 11:38:55 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2018-09-28 13:14:32 +0200
commit248f70d425c4cd865d4bd54ab1134ccff8b68e36 (patch)
treed814ffd77546d577ba135b3735e86a12ba1ca871 /apt-pkg/cachefile.cc
parent3de7454c796f245371c33076ae01529d6d36d715 (diff)
pkgCacheFile: Only unlock in destructor if locked before
pkgCacheFile's destructor unlocks the system, which is confusing if you did not open the cachefile with WithLock set. Create a private data instance that holds the value of WithLock. This regression was introduced in commit b2e465d6d32d2dc884f58b94acb7e35f671a87fe: Join with aliencode Author: jgg Date: 2001-02-20 07:03:16 GMT Join with aliencode by replacing a "Lock" member that was only initialized when the lock was taken by calls to Lock, UnLock; with the latter also taking place if the former did not occur. Regression-Of: b2e465d6d32d2dc884f58b94acb7e35f671a87fe LP: #1794053 (cherry picked from commit e02297b8e22dae04872fe6fab6dba966de65dbba)
Diffstat (limited to 'apt-pkg/cachefile.cc')
-rw-r--r--apt-pkg/cachefile.cc23
1 files changed, 19 insertions, 4 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index c070f4b9e..b0c15f543 100644
--- a/apt-pkg/cachefile.cc
+++ b/apt-pkg/cachefile.cc
@@ -36,12 +36,18 @@
#include <apti18n.h>
/*}}}*/
+
+struct pkgCacheFile::Private
+{
+ bool WithLock = false;
+};
+
// CacheFile::CacheFile - Constructor /*{{{*/
-pkgCacheFile::pkgCacheFile() : d(NULL), ExternOwner(false), Map(NULL), Cache(NULL),
+pkgCacheFile::pkgCacheFile() : d(new Private()), ExternOwner(false), Map(NULL), Cache(NULL),
DCache(NULL), SrcList(NULL), Policy(NULL)
{
}
-pkgCacheFile::pkgCacheFile(pkgDepCache * const Owner) : d(NULL), ExternOwner(true),
+pkgCacheFile::pkgCacheFile(pkgDepCache * const Owner) : d(new Private()), ExternOwner(true),
Map(&Owner->GetCache().GetMap()), Cache(&Owner->GetCache()),
DCache(Owner), SrcList(NULL), Policy(NULL)
{
@@ -60,8 +66,10 @@ pkgCacheFile::~pkgCacheFile()
}
delete Policy;
delete SrcList;
- if (ExternOwner == false)
+ if (d->WithLock == true)
_system->UnLock(true);
+
+ delete d;
}
/*}}}*/
// CacheFile::BuildCaches - Open and build the cache files /*{{{*/
@@ -98,8 +106,11 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
}
if (WithLock == true)
+ {
if (_system->Lock() == false)
return false;
+ d->WithLock = true;
+ }
if (_error->PendingError() == true)
return false;
@@ -338,7 +349,11 @@ void pkgCacheFile::Close()
ExternOwner = false;
delete Policy;
delete SrcList;
- _system->UnLock(true);
+ if (d->WithLock == true)
+ {
+ _system->UnLock(true);
+ d->WithLock = false;
+ }
Map = NULL;
DCache = NULL;