From e02297b8e22dae04872fe6fab6dba966de65dbba Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 24 Sep 2018 11:38:55 +0200 Subject: 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 --- apt-pkg/cachefile.cc | 23 +++++++++++++++++++---- apt-pkg/cachefile.h | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index a22804c36..9a1a6cfa9 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -35,12 +35,18 @@ #include /*}}}*/ + +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) { @@ -59,8 +65,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 /*{{{*/ @@ -97,8 +105,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; @@ -337,7 +348,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; diff --git a/apt-pkg/cachefile.h b/apt-pkg/cachefile.h index 097876b3a..ed5d5c57c 100644 --- a/apt-pkg/cachefile.h +++ b/apt-pkg/cachefile.h @@ -36,8 +36,9 @@ class OpProgress; class pkgCacheFile { + struct Private; /** \brief dpointer placeholder (for later in case we need it) */ - void * const d; + Private *const d; bool ExternOwner; protected: -- cgit v1.2.3-18-g5258