Browse Source

fix memory leaks reported by -fsanitize

Various small leaks here and there. Nothing particularily big, but still
good to fix. Found by the sanitizers while running our testcases.

Reported-By: gcc -fsanitize
Git-Dch: Ignore
tags/debian/1.1.exp9
David Kalnischkies 6 years ago
parent
commit
3d8232bf97
26 changed files with 190 additions and 138 deletions
  1. +33
    -24
      apt-pkg/acquire-item.cc
  2. +23
    -22
      apt-pkg/acquire-item.h
  3. +1
    -1
      apt-pkg/acquire-worker.cc
  4. +2
    -2
      apt-pkg/cachefile.cc
  5. +2
    -0
      apt-pkg/contrib/cdromutl.cc
  6. +2
    -0
      apt-pkg/contrib/gpgv.cc
  7. +1
    -1
      apt-pkg/deb/debmetaindex.cc
  8. +4
    -0
      apt-pkg/deb/debrecords.cc
  9. +4
    -0
      apt-pkg/deb/dpkgpm.cc
  10. +4
    -1
      apt-pkg/indexrecords.cc
  11. +10
    -3
      apt-pkg/tagfile.cc
  12. +1
    -1
      apt-pkg/tagfile.h
  13. +9
    -4
      apt-private/private-cacheset.h
  14. +14
    -9
      apt-private/private-output.cc
  15. +2
    -0
      buildlib/environment.mak.in
  16. +1
    -0
      cmdline/apt-cache.cc
  17. +3
    -5
      cmdline/apt-get.cc
  18. +35
    -34
      ftparchive/apt-ftparchive.cc
  19. +1
    -0
      ftparchive/cachedb.cc
  20. +20
    -11
      ftparchive/writer.cc
  21. +5
    -9
      ftparchive/writer.h
  22. +3
    -0
      test/integration/framework
  23. +3
    -4
      test/libapt/cdrom_test.cc
  24. +3
    -4
      test/libapt/file-helpers.cc
  25. +1
    -1
      test/libapt/file-helpers.h
  26. +3
    -2
      test/libapt/sourcelist_test.cc

+ 33
- 24
apt-pkg/acquire-item.cc View File

@@ -109,7 +109,7 @@ static std::string GetDiffsPatchFileName(std::string const &Final) /*{{{*/
}
/*}}}*/

static bool AllowInsecureRepositories(indexRecords const * const MetaIndexParser, pkgAcqMetaBase * const TransactionManager, pkgAcquire::Item * const I) /*{{{*/
static bool AllowInsecureRepositories(indexRecords const * const MetaIndexParser, pkgAcqMetaClearSig * const TransactionManager, pkgAcquire::Item * const I) /*{{{*/
{
if(MetaIndexParser->IsAlwaysTrusted() || _config->FindB("Acquire::AllowInsecureRepositories") == true)
return true;
@@ -661,7 +661,7 @@ std::string pkgAcquire::Item::HashSum() const /*{{{*/
/*}}}*/

pkgAcqTransactionItem::pkgAcqTransactionItem(pkgAcquire * const Owner, /*{{{*/
pkgAcqMetaBase * const transactionManager, IndexTarget const &target) :
pkgAcqMetaClearSig * const transactionManager, IndexTarget const &target) :
pkgAcquire::Item(Owner), d(NULL), Target(target), TransactionManager(transactionManager)
{
if (TransactionManager != this)
@@ -680,12 +680,11 @@ HashStringList pkgAcqTransactionItem::GetExpectedHashesFor(std::string const &Me

// AcqMetaBase - Constructor /*{{{*/
pkgAcqMetaBase::pkgAcqMetaBase(pkgAcquire * const Owner,
pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaClearSig * const TransactionManager,
std::vector<IndexTarget> const &IndexTargets,
IndexTarget const &DataTarget,
indexRecords * const MetaIndexParser)
IndexTarget const &DataTarget)
: pkgAcqTransactionItem(Owner, TransactionManager, DataTarget), d(NULL),
MetaIndexParser(MetaIndexParser), LastMetaIndexParser(NULL), IndexTargets(IndexTargets),
IndexTargets(IndexTargets),
AuthPass(false), IMSHit(false)
{
}
@@ -1047,7 +1046,7 @@ bool pkgAcqMetaBase::VerifyVendor(string const &Message) /*{{{*/
std::string errmsg;
strprintf(errmsg,
// TRANSLATOR: The first %s is the URL of the bad Release file, the second is
// the time since then the file is invalid - formated in the same way as in
// the time since then the file is invalid - formatted in the same way as in
// the download progress display (e.g. 7d 3h 42min 1s)
_("Release file for %s is expired (invalid since %s). "
"Updates for this repository will not be applied."),
@@ -1098,16 +1097,19 @@ bool pkgAcqMetaBase::VerifyVendor(string const &Message) /*{{{*/
return true;
}
/*}}}*/
pkgAcqMetaBase::~pkgAcqMetaBase() {}
pkgAcqMetaBase::~pkgAcqMetaBase()
{
}

pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire * const Owner, /*{{{*/
IndexTarget const &ClearsignedTarget,
IndexTarget const &DetachedDataTarget, IndexTarget const &DetachedSigTarget,
std::vector<IndexTarget> const &IndexTargets,
indexRecords * const MetaIndexParser) :
pkgAcqMetaIndex(Owner, this, ClearsignedTarget, DetachedSigTarget, IndexTargets, MetaIndexParser),
pkgAcqMetaIndex(Owner, this, ClearsignedTarget, DetachedSigTarget, IndexTargets),
d(NULL), ClearsignedTarget(ClearsignedTarget),
DetachedDataTarget(DetachedDataTarget)
DetachedDataTarget(DetachedDataTarget),
MetaIndexParser(MetaIndexParser), LastMetaIndexParser(NULL)
{
// index targets + (worst case:) Release/Release.gpg
ExpectedAdditionalItems = IndexTargets.size() + 2;
@@ -1116,6 +1118,10 @@ pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire * const Owner, /*{{{*/
/*}}}*/
pkgAcqMetaClearSig::~pkgAcqMetaClearSig() /*{{{*/
{
if (MetaIndexParser != NULL)
delete MetaIndexParser;
if (LastMetaIndexParser != NULL)
delete LastMetaIndexParser;
}
/*}}}*/
// pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers /*{{{*/
@@ -1180,7 +1186,7 @@ void pkgAcqMetaClearSig::Failed(string const &Message,pkgAcquire::MethodConfig c
TransactionManager->TransactionStageRemoval(this, GetFinalFilename());
Status = StatDone;

new pkgAcqMetaIndex(Owner, TransactionManager, DetachedDataTarget, DetachedSigTarget, IndexTargets, TransactionManager->MetaIndexParser);
new pkgAcqMetaIndex(Owner, TransactionManager, DetachedDataTarget, DetachedSigTarget, IndexTargets);
}
else
{
@@ -1240,12 +1246,11 @@ void pkgAcqMetaClearSig::Failed(string const &Message,pkgAcquire::MethodConfig c
/*}}}*/

pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire * const Owner, /*{{{*/
pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &DataTarget,
IndexTarget const &DetachedSigTarget,
vector<IndexTarget> const &IndexTargets,
indexRecords * const MetaIndexParser) :
pkgAcqMetaBase(Owner, TransactionManager, IndexTargets, DataTarget, MetaIndexParser), d(NULL),
vector<IndexTarget> const &IndexTargets) :
pkgAcqMetaBase(Owner, TransactionManager, IndexTargets, DataTarget), d(NULL),
DetachedSigTarget(DetachedSigTarget)
{
if(_config->FindB("Debug::Acquire::Transaction", false) == true)
@@ -1324,7 +1329,7 @@ pkgAcqMetaIndex::~pkgAcqMetaIndex() {}

// AcqMetaSig::AcqMetaSig - Constructor /*{{{*/
pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire * const Owner,
pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target,
pkgAcqMetaIndex * const MetaIndex) :
pkgAcqTransactionItem(Owner, TransactionManager, Target), d(NULL), MetaIndex(MetaIndex)
@@ -1487,7 +1492,7 @@ void pkgAcqMetaSig::Failed(string const &Message,pkgAcquire::MethodConfig const

// AcqBaseIndex - Constructor /*{{{*/
pkgAcqBaseIndex::pkgAcqBaseIndex(pkgAcquire * const Owner,
pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target)
: pkgAcqTransactionItem(Owner, TransactionManager, Target), d(NULL)
{
@@ -1503,9 +1508,9 @@ pkgAcqBaseIndex::~pkgAcqBaseIndex() {}
* the original packages file
*/
pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire * const Owner,
pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target)
: pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL)
: pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL), diffs(NULL)
{
Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);

@@ -1840,7 +1845,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
new pkgAcqIndexDiffs(Owner, TransactionManager, Target, available_patches);
else
{
std::vector<pkgAcqIndexMergeDiffs*> *diffs = new std::vector<pkgAcqIndexMergeDiffs*>(available_patches.size());
diffs = new std::vector<pkgAcqIndexMergeDiffs*>(available_patches.size());
for(size_t i = 0; i < available_patches.size(); ++i)
(*diffs)[i] = new pkgAcqIndexMergeDiffs(Owner, TransactionManager,
Target,
@@ -1896,7 +1901,11 @@ void pkgAcqDiffIndex::Done(string const &Message,HashStringList const &Hashes, /
return;
}
/*}}}*/
pkgAcqDiffIndex::~pkgAcqDiffIndex() {}
pkgAcqDiffIndex::~pkgAcqDiffIndex()
{
if (diffs != NULL)
delete diffs;
}

// AcqIndexDiffs::AcqIndexDiffs - Constructor /*{{{*/
// ---------------------------------------------------------------------
@@ -1904,7 +1913,7 @@ pkgAcqDiffIndex::~pkgAcqDiffIndex() {}
* for each diff and the index
*/
pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire * const Owner,
pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target,
vector<DiffInfo> const &diffs)
: pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL),
@@ -2127,7 +2136,7 @@ pkgAcqIndexDiffs::~pkgAcqIndexDiffs() {}

// AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor /*{{{*/
pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire * const Owner,
pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target,
DiffInfo const &patch,
std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches)
@@ -2272,7 +2281,7 @@ pkgAcqIndexMergeDiffs::~pkgAcqIndexMergeDiffs() {}

// AcqIndex::AcqIndex - Constructor /*{{{*/
pkgAcqIndex::pkgAcqIndex(pkgAcquire * const Owner,
pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target)
: pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL), Stage(STAGE_DOWNLOAD)
{


+ 23
- 22
apt-pkg/acquire-item.h View File

@@ -46,7 +46,8 @@
class indexRecords;
class pkgRecords;
class pkgSourceList;
class pkgAcqMetaBase;
class pkgAcqMetaClearSig;
class pkgAcqIndexMergeDiffs;

class pkgAcquire::Item : public WeakPointable /*{{{*/
/** \brief Represents the process by which a pkgAcquire object should
@@ -339,6 +340,7 @@ class pkgAcquire::Item : public WeakPointable /*{{{*/
void * const d;

friend class pkgAcqMetaBase;
friend class pkgAcqMetaClearSig;
};
/*}}}*/
class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item /*{{{*/
@@ -356,7 +358,7 @@ class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item /*{{{*/
std::string PartialFile;

/** \brief TransactionManager */
pkgAcqMetaBase * const TransactionManager;
pkgAcqMetaClearSig * const TransactionManager;

enum TransactionStates {
TransactionCommit,
@@ -370,10 +372,11 @@ class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item /*{{{*/
virtual bool HashesRequired() const;


pkgAcqTransactionItem(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager, IndexTarget const &Target);
pkgAcqTransactionItem(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager, IndexTarget const &Target);
virtual ~pkgAcqTransactionItem();

friend class pkgAcqMetaBase;
friend class pkgAcqMetaClearSig;
};
/*}}}*/
class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem /*{{{*/
@@ -383,12 +386,6 @@ class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem /*{{{*/
protected:
std::vector<pkgAcqTransactionItem*> Transaction;

public:
/** \brief A package-system-specific parser for the meta-index file. */
indexRecords *MetaIndexParser;
indexRecords *LastMetaIndexParser;
protected:

/** \brief The index files which should be looked up in the meta-index
* and then downloaded.
*/
@@ -473,10 +470,9 @@ class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem /*{{{*/
/** \brief Get the full pathname of the final file for the current URI */
virtual std::string GetFinalFilename() const;

pkgAcqMetaBase(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaBase(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
std::vector<IndexTarget> const &IndexTargets,
IndexTarget const &DataTarget,
indexRecords* const MetaIndexParser);
IndexTarget const &DataTarget);
virtual ~pkgAcqMetaBase();
};
/*}}}*/
@@ -509,9 +505,9 @@ class APT_HIDDEN pkgAcqMetaIndex : public pkgAcqMetaBase
virtual void Finished();

/** \brief Create a new pkgAcqMetaIndex. */
pkgAcqMetaIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
pkgAcqMetaIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &DataTarget, IndexTarget const &DetachedSigTarget,
std::vector<IndexTarget> const &IndexTargets, indexRecords * const MetaIndexParser);
std::vector<IndexTarget> const &IndexTargets);
virtual ~pkgAcqMetaIndex();

friend class pkgAcqMetaSig;
@@ -548,8 +544,8 @@ class APT_HIDDEN pkgAcqMetaSig : public pkgAcqTransactionItem
pkgAcquire::MethodConfig const * const Cnf);

/** \brief Create a new pkgAcqMetaSig. */
pkgAcqMetaSig(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager, IndexTarget const &Target,
pkgAcqMetaIndex * const MetaIndex);
pkgAcqMetaSig(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target, pkgAcqMetaIndex * const MetaIndex);
virtual ~pkgAcqMetaSig();
};
/*}}}*/
@@ -561,7 +557,11 @@ class APT_HIDDEN pkgAcqMetaClearSig : public pkgAcqMetaIndex
IndexTarget const ClearsignedTarget;
IndexTarget const DetachedDataTarget;

public:
public:
/** \brief A package-system-specific parser for the meta-index file. */
indexRecords *MetaIndexParser;
indexRecords *LastMetaIndexParser;

virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
virtual std::string Custom600Headers() const;
virtual void Done(std::string const &Message, HashStringList const &Hashes,
@@ -586,7 +586,7 @@ class APT_HIDDEN pkgAcqBaseIndex : public pkgAcqTransactionItem
/** \brief Get the full pathname of the final file for the current URI */
virtual std::string GetFinalFilename() const;

pkgAcqBaseIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
pkgAcqBaseIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target);
virtual ~pkgAcqBaseIndex();
};
@@ -603,6 +603,7 @@ class APT_HIDDEN pkgAcqBaseIndex : public pkgAcqTransactionItem
class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
{
void * const d;
std::vector<pkgAcqIndexMergeDiffs*> * diffs;

protected:
/** \brief If \b true, debugging information will be written to std::clog. */
@@ -650,7 +651,7 @@ class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
*
* \param ShortDesc A short description of the list file to download.
*/
pkgAcqDiffIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
pkgAcqDiffIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target);
virtual ~pkgAcqDiffIndex();
private:
@@ -749,7 +750,7 @@ class APT_HIDDEN pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
* \param allPatches contains all related items so that each item can
* check if it was the last one to complete the download step
*/
pkgAcqIndexMergeDiffs(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
pkgAcqIndexMergeDiffs(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target, DiffInfo const &patch,
std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
virtual ~pkgAcqIndexMergeDiffs();
@@ -863,7 +864,7 @@ class APT_HIDDEN pkgAcqIndexDiffs : public pkgAcqBaseIndex
* should be ordered so that each diff appears before any diff
* that depends on it.
*/
pkgAcqIndexDiffs(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
pkgAcqIndexDiffs(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target,
std::vector<DiffInfo> const &diffs=std::vector<DiffInfo>());
virtual ~pkgAcqIndexDiffs();
@@ -941,7 +942,7 @@ class APT_HIDDEN pkgAcqIndex : public pkgAcqBaseIndex
virtual std::string DescURI() const {return Desc.URI;};
virtual std::string GetMetaKey() const;

pkgAcqIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
pkgAcqIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
IndexTarget const &Target);
virtual ~pkgAcqIndex();



+ 1
- 1
apt-pkg/acquire-worker.cc View File

@@ -722,7 +722,7 @@ void pkgAcquire::Worker::PrepareFiles(char const * const caller, pkgAcquire::Que
unlink(Owner->DestFile.c_str());
if (link(filename.c_str(), Owner->DestFile.c_str()) != 0)
{
// diferent mounts can't happen for us as we download to lists/ by default,
// different mounts can't happen for us as we download to lists/ by default,
// but if the system is reused by others the locations can potentially be on
// different disks, so use symlink as poor-men replacement.
// FIXME: Real copying as last fallback, but that is costly, so offload to a method preferable


+ 2
- 2
apt-pkg/cachefile.cc View File

@@ -65,8 +65,8 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)

if (_config->FindB("pkgCacheFile::Generate", true) == false)
{
Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
FileFd file(_config->FindFile("Dir::Cache::pkgcache"), FileFd::ReadOnly);
Map = new MMap(file, MMap::Public|MMap::ReadOnly);
Cache = new pkgCache(Map);
if (_error->PendingError() == true)
return false;


+ 2
- 0
apt-pkg/contrib/cdromutl.cc View File

@@ -287,9 +287,11 @@ string FindMountPointForDevice(const char *devnode)
fclose(f);
// unescape the \0XXX chars in the path
string mount_point = out[1];
free(line);
return DeEscapeString(mount_point);
}
fclose(f);
free(line);
}

return string();


+ 2
- 0
apt-pkg/contrib/gpgv.cc View File

@@ -296,6 +296,8 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile,
// all the rest is whitespace, unsigned garbage or additional message blocks we ignore
}
fclose(in);
if (buf != NULL)
free(buf);

if (found_signature == true)
return _error->Error("Signature in file %s wasn't closed", InFile.c_str());


+ 1
- 1
apt-pkg/deb/debmetaindex.cc View File

@@ -270,7 +270,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const
// special case for --print-uris
std::vector<IndexTarget> const targets = GetIndexTargets();
#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map<std::string,std::string>())
pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner,
pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner,
APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
targets, iR);
#undef APT_TARGET


+ 4
- 0
apt-pkg/deb/debrecords.cc View File

@@ -42,10 +42,14 @@ debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
// RecordParser::Jump - Jump to a specific record /*{{{*/
bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
{
if (Ver.end() == true)
return false;
return Tags.Jump(Section,Ver->Offset);
}
bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
{
if (Desc.end() == true)
return false;
return Tags.Jump(Section,Desc->Offset);
}
/*}}}*/


+ 4
- 0
apt-pkg/deb/dpkgpm.cc View File

@@ -1484,6 +1484,10 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
a != Args.end(); ++a)
clog << *a << ' ';
clog << endl;
for (std::vector<char *>::const_iterator p = Packages.begin();
p != Packages.end(); ++p)
free(*p);
Packages.clear();
continue;
}
Args.push_back(NULL);


+ 4
- 1
apt-pkg/indexrecords.cc View File

@@ -278,4 +278,7 @@ indexRecords::indexRecords(const string &ExpectedDist) :
{
}

indexRecords::~indexRecords() {}
indexRecords::~indexRecords() {
for (std::map<std::string, checkSum*>::const_iterator S = Entries.begin(); S != Entries.end(); ++S)
delete S->second;
}

+ 10
- 3
apt-pkg/tagfile.cc View File

@@ -34,8 +34,10 @@ class pkgTagFilePrivate
public:
void Reset(FileFd * const pFd, unsigned long long const pSize)
{
Fd = pFd;
if (Buffer != NULL)
free(Buffer);
Buffer = NULL;
Fd = pFd;
Start = NULL;
End = NULL;
Done = false;
@@ -43,7 +45,7 @@ public:
Size = pSize;
}

pkgTagFilePrivate(FileFd * const pFd, unsigned long long const Size)
pkgTagFilePrivate(FileFd * const pFd, unsigned long long const Size) : Buffer(NULL)
{
Reset(pFd, Size);
}
@@ -54,6 +56,12 @@ public:
bool Done;
unsigned long long iOffset;
unsigned long long Size;

~pkgTagFilePrivate()
{
if (Buffer != NULL)
free(Buffer);
}
};

class pkgTagSectionPrivate
@@ -127,7 +135,6 @@ void pkgTagFile::Init(FileFd * const pFd,unsigned long long Size)
/* */
pkgTagFile::~pkgTagFile()
{
free(d->Buffer);
delete d;
}
/*}}}*/


+ 1
- 1
apt-pkg/tagfile.h View File

@@ -136,7 +136,7 @@ class pkgTagSection
*
* @param File to write the section to
* @param Order in which tags should appear in the file
* @param Rewrite is a set of tags to be renamed, rewitten and/or removed
* @param Rewrite is a set of tags to be renamed, rewritten and/or removed
* @return \b true if successful, otherwise \b false
*/
bool Write(FileFd &File, char const * const * const Order = NULL, std::vector<Tag> const &Rewrite = std::vector<Tag>()) const;


+ 9
- 4
apt-private/private-cacheset.h View File

@@ -32,10 +32,15 @@ struct VersionSortDescriptionLocality
bool operator () (const pkgCache::VerIterator &v_lhs,
const pkgCache::VerIterator &v_rhs)
{
pkgCache::DescFile *A = v_lhs.TranslatedDescription().FileList();
pkgCache::DescFile *B = v_rhs.TranslatedDescription().FileList();
if (A == 0 && B == 0)
return false;
pkgCache::DescFile const *A = NULL;
pkgCache::DescFile const *B = NULL;
if (v_lhs->DescriptionList != 0)
A = v_lhs.TranslatedDescription().FileList();
if (v_rhs->DescriptionList != 0)
B = v_rhs.TranslatedDescription().FileList();

if (A == 0 && B == 0)
return false;

if (A == 0)
return true;


+ 14
- 9
apt-private/private-output.cc View File

@@ -199,10 +199,12 @@ static std::string GetShortDescription(pkgCacheFile &CacheFile, pkgRecords &reco
std::string ShortDescription = "(none)";
if(ver)
{
pkgCache::DescIterator Desc = ver.TranslatedDescription();
pkgRecords::Parser & parser = records.Lookup(Desc.FileList());

ShortDescription = parser.ShortDesc();
pkgCache::DescIterator const Desc = ver.TranslatedDescription();
if (Desc.end() == false)
{
pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
ShortDescription = parser.ShortDesc();
}
}
return ShortDescription;
}
@@ -222,11 +224,14 @@ static std::string GetLongDescription(pkgCacheFile &CacheFile, pkgRecords &recor
return EmptyDescription;

pkgCache::DescIterator const Desc = ver.TranslatedDescription();
pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
std::string const longdesc = parser.LongDesc();
if (longdesc.empty() == true)
return EmptyDescription;
return SubstVar(longdesc, "\n ", "\n ");
if (Desc.end() == false)
{
pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
std::string const longdesc = parser.LongDesc();
if (longdesc.empty() == false)
return SubstVar(longdesc, "\n ", "\n ");
}
return EmptyDescription;
}
/*}}}*/
void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/


+ 2
- 0
buildlib/environment.mak.in View File

@@ -16,6 +16,8 @@ CXXFLAGS+= -Wctor-dtor-privacy -Wdisabled-optimization -Winit-self -Wmissing-inc
#CXXFLAGS+= -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn
# gcc reports currently lots of them at the end of file - unknown reason
CXXFLAGS+= -Wno-deprecated-declarations
# sanitize options to be enabled for testing
#CXXFLAGS+= -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr
# a bit too pedantic to be run by default
#CXXFLAGS+= -Wpedantic -Wno-long-long -Wno-vla -Wno-variadic-macros
NUM_PROCS = @NUM_PROCS@


+ 1
- 0
cmdline/apt-cache.cc View File

@@ -1484,6 +1484,7 @@ static bool Search(CommandLine &CmdL)
delete [] PatternMatch;
for (unsigned I = 0; I != NumPatterns; I++)
regfree(&Patterns[I]);
delete [] Patterns;
if (ferror(stdout))
return _error->Error("Write to stdout failed");
return true;


+ 3
- 5
cmdline/apt-get.cc View File

@@ -1015,9 +1015,6 @@ static bool DoBuildDep(CommandLine &CmdL)
pkgSourceList *List = Cache.GetSourceList();
// Create the text record parsers
#if APT_PKG_ABI < 413
pkgRecords Recs(Cache);
#endif
pkgSrcRecords SrcRecs(*List);
if (_error->PendingError() == true)
return false;
@@ -1039,6 +1036,7 @@ static bool DoBuildDep(CommandLine &CmdL)
{
string Src;
pkgSrcRecords::Parser *Last = 0;
SPtr<pkgSrcRecords::Parser> LastOwner;

// an unpacked debian source tree
using APT::String::Startswith;
@@ -1050,7 +1048,7 @@ static bool DoBuildDep(CommandLine &CmdL)
std::string TypeName = "debian/control File Source Index";
pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
if(Type != NULL)
Last = Type->CreateSrcPkgParser(*I);
LastOwner = Last = Type->CreateSrcPkgParser(*I);
}
// if its a local file (e.g. .dsc) use this
else if (FileExists(*I))
@@ -1061,7 +1059,7 @@ static bool DoBuildDep(CommandLine &CmdL)
string TypeName = flExtension(*I) + " File Source Index";
pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
if(Type != NULL)
Last = Type->CreateSrcPkgParser(*I);
LastOwner = Last = Type->CreateSrcPkgParser(*I);
} else {
// normal case, search the cache for the source file
#if APT_PKG_ABI >= 413


+ 35
- 34
ftparchive/apt-ftparchive.cc View File

@@ -180,7 +180,7 @@ bool PackageMap::GenPackages(Configuration &Setup,struct CacheDB::Stats &Stats)
// Create a package writer object.
MultiCompress Comp(flCombine(ArchiveDir,PkgFile),
PkgCompress,Permissions);
PackagesWriter Packages(&Comp.Input, flCombine(CacheDir,BinCacheDB),
PackagesWriter Packages(&Comp.Input, TransWriter, flCombine(CacheDir,BinCacheDB),
flCombine(OverrideDir,BinOverride),
flCombine(OverrideDir,ExtraOverride),
Arch);
@@ -193,7 +193,6 @@ bool PackageMap::GenPackages(Configuration &Setup,struct CacheDB::Stats &Stats)
Packages.DirStrip = ArchiveDir;
Packages.InternalPrefix = flCombine(ArchiveDir,InternalPrefix);

Packages.TransWriter = TransWriter;
Packages.LongDescription = LongDesc;

Packages.Stats.DeLinkBytes = Stats.DeLinkBytes;
@@ -457,7 +456,7 @@ bool PackageMap::GenContents(Configuration &Setup,
// ---------------------------------------------------------------------
/* This populates the PkgList with all the possible permutations of the
section/arch lists. */
static void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup)
static void LoadTree(vector<PackageMap> &PkgList, std::vector<TranslationWriter*> &TransList, Configuration &Setup)
{
// Load the defaults
string DDir = Setup.Find("TreeDefault::Directory",
@@ -508,16 +507,7 @@ static void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup)
{NULL, NULL}};
mode_t const Perms = Block.FindI("FileMode", Permissions);
bool const LongDesc = Block.FindB("LongDescription", LongDescription);
TranslationWriter *TransWriter;
if (DTrans.empty() == false && LongDesc == false)
{
string const TranslationFile = flCombine(Setup.FindDir("Dir::ArchiveDir"),
SubstVar(Block.Find("Translation", DTrans.c_str()), Vars));
string const TransCompress = Block.Find("Translation::Compress", TranslationCompress);
TransWriter = new TranslationWriter(TranslationFile, TransCompress, Perms);
}
else
TransWriter = NULL;
TranslationWriter *TransWriter = NULL;

string const Tmp2 = Block.Find("Architectures");
const char *Archs = Tmp2.c_str();
@@ -546,27 +536,34 @@ static void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup)
Itm.Tag = SubstVar("$(DIST)/$(SECTION)/$(ARCH)",Vars);
Itm.Arch = Arch;
Itm.LongDesc = LongDesc;
if (TransWriter != NULL)
if (TransWriter == NULL && DTrans.empty() == false && LongDesc == false && DTrans != "/dev/null")
{
TransWriter->IncreaseRefCounter();
Itm.TransWriter = TransWriter;
string const TranslationFile = flCombine(Setup.FindDir("Dir::ArchiveDir"),
SubstVar(Block.Find("Translation", DTrans.c_str()), Vars));
string const TransCompress = Block.Find("Translation::Compress", TranslationCompress);
TransWriter = new TranslationWriter(TranslationFile, TransCompress, Perms);
TransList.push_back(TransWriter);
}
Itm.TransWriter = TransWriter;
Itm.Contents = SubstVar(Block.Find("Contents",DContents.c_str()),Vars);
Itm.ContentsHead = SubstVar(Block.Find("Contents::Header",DContentsH.c_str()),Vars);
Itm.FLFile = SubstVar(Block.Find("FileList",DFLFile.c_str()),Vars);
Itm.ExtraOverride = SubstVar(Block.Find("ExtraOverride"),Vars);
}

Itm.GetGeneral(Setup,Block);
Itm.GetGeneral(Setup,Block);
PkgList.push_back(Itm);
}
// we didn't use this TransWriter, so we can release it
if (TransWriter != NULL && TransWriter->GetRefCounter() == 0)
delete TransWriter;
}

Top = Top->Next;
}
}
}
/*}}}*/
static void UnloadTree(std::vector<TranslationWriter*> const &Trans) /*{{{*/
{
for (std::vector<TranslationWriter*>::const_reverse_iterator T = Trans.rbegin(); T != Trans.rend(); ++T)
delete *T;
}
/*}}}*/
// LoadBinDir - Load a 'bindirectory' section from the Generate Config /*{{{*/
@@ -671,7 +668,7 @@ static bool SimpleGenPackages(CommandLine &CmdL)
Override = CmdL.FileList[2];
// Create a package writer object.
PackagesWriter Packages(NULL, _config->Find("APT::FTPArchive::DB"),
PackagesWriter Packages(NULL, NULL, _config->Find("APT::FTPArchive::DB"),
Override, "", _config->Find("APT::FTPArchive::Architecture"));
if (_error->PendingError() == true)
return false;
@@ -844,12 +841,6 @@ static bool DoGeneratePackagesAndSources(Configuration &Setup,
delete [] List;
}

// close the Translation master files
for (vector<PackageMap>::reverse_iterator I = PkgList.rbegin(); I != PkgList.rend(); ++I)
if (I->TransWriter != NULL && I->TransWriter->DecreaseRefCounter() == 0)
delete I->TransWriter;

return true;
}

@@ -940,7 +931,8 @@ static bool Generate(CommandLine &CmdL)
return false;

vector<PackageMap> PkgList;
LoadTree(PkgList,Setup);
std::vector<TranslationWriter*> TransList;
LoadTree(PkgList, TransList, Setup);
LoadBinDir(PkgList,Setup);

// Sort by cache DB to improve IO locality.
@@ -951,7 +943,10 @@ static bool Generate(CommandLine &CmdL)
if (_config->FindB("APT::FTPArchive::ContentsOnly", false) == false)
{
if(DoGeneratePackagesAndSources(Setup, PkgList, SrcStats, Stats, CmdL) == false)
{
UnloadTree(TransList);
return false;
}
} else {
c1out << "Skipping Packages/Sources generation" << endl;
}
@@ -959,7 +954,10 @@ static bool Generate(CommandLine &CmdL)
// do Contents if needed
if (_config->FindB("APT::FTPArchive::Contents", true) == true)
if (DoGenerateContents(Setup, PkgList, CmdL) == false)
return false;
{
UnloadTree(TransList);
return false;
}

struct timeval NewTime;
gettimeofday(&NewTime,0);
@@ -968,6 +966,7 @@ static bool Generate(CommandLine &CmdL)
c1out << "Done. " << SizeToStr(Stats.Bytes) << "B in " << Stats.Packages
<< " archives. Took " << TimeToStr((long)Delta) << endl;

UnloadTree(TransList);
return true;
}

@@ -984,9 +983,12 @@ static bool Clean(CommandLine &CmdL)
Configuration Setup;
if (ReadConfigFile(Setup,CmdL.FileList[1],true) == false)
return false;
// we don't need translation creation here
Setup.Set("TreeDefault::Translation", "/dev/null");

vector<PackageMap> PkgList;
LoadTree(PkgList,Setup);
std::vector<TranslationWriter*> TransList;
LoadTree(PkgList, TransList, Setup);
LoadBinDir(PkgList,Setup);

// Sort by cache DB to improve IO locality.
@@ -1007,14 +1009,13 @@ static bool Clean(CommandLine &CmdL)
_error->DumpErrors();
if (DB_SRC.Clean() == false)
_error->DumpErrors();
string CacheDB = I->BinCacheDB;
string SrcCacheDB = I->SrcCacheDB;
while(I != PkgList.end() &&
I->BinCacheDB == CacheDB &&
I->SrcCacheDB == SrcCacheDB)
++I;

}



+ 1
- 0
ftparchive/cachedb.cc View File

@@ -45,6 +45,7 @@ CacheDB::~CacheDB()
{
ReadyDB();
delete DebFile;
CloseFile();
}

// CacheDB::ReadyDB - Ready the DB2 /*{{{*/


+ 20
- 11
ftparchive/writer.cc View File

@@ -69,22 +69,29 @@ static void ConfigToDoHashes(unsigned int &DoHashes, std::string const &Conf)
/*}}}*/

// FTWScanner::FTWScanner - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
FTWScanner::FTWScanner(FileFd * const GivenOutput, string const &Arch): Arch(Arch), DoHashes(~0)
{
if (GivenOutput == NULL)
{
Output = new FileFd;
OwnsOutput = true;
Output->OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
}
else
{
Output = GivenOutput;
OwnsOutput = false;
}
ErrorPrinted = false;
NoLinkAct = !_config->FindB("APT::FTPArchive::DeLinkAct",true);
ConfigToDoHashes(DoHashes, "APT::FTPArchive");
}
/*}}}*/
FTWScanner::~FTWScanner()
{
if (Output != NULL && OwnsOutput)
delete Output;
}
// FTWScanner::Scanner - FTW Scanner /*{{{*/
// ---------------------------------------------------------------------
/* This is the FTW scanner, it processes each directory element in the
@@ -324,9 +331,10 @@ bool FTWScanner::Delink(string &FileName,const char *OriginalPath,
// PackagesWriter::PackagesWriter - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
PackagesWriter::PackagesWriter(FileFd * const GivenOutput, string const &DB,string const &Overrides,string const &ExtOverrides,
string const &Arch) :
FTWScanner(GivenOutput, Arch), Db(DB), Stats(Db.Stats), TransWriter(NULL)
PackagesWriter::PackagesWriter(FileFd * const GivenOutput, TranslationWriter * const transWriter,
string const &DB,string const &Overrides,string const &ExtOverrides,
string const &Arch) :
FTWScanner(GivenOutput, Arch), Db(DB), Stats(Db.Stats), TransWriter(transWriter)
{
SetExts(".deb .udeb");
DeLinkLimit = 0;
@@ -377,7 +385,6 @@ bool FTWScanner::SetExts(string const &Vals)

return true;
}

/*}}}*/
// PackagesWriter::DoPackage - Process a single package /*{{{*/
// ---------------------------------------------------------------------
@@ -524,12 +531,16 @@ bool PackagesWriter::DoPackage(string FileName)
return Db.Finish();
}
/*}}}*/
PackagesWriter::~PackagesWriter() /*{{{*/
{
}
/*}}}*/

// TranslationWriter::TranslationWriter - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* Create a Translation-Master file for this Packages file */
TranslationWriter::TranslationWriter(string const &File, string const &TransCompress,
mode_t const &Permissions) : RefCounter(0)
mode_t const &Permissions) : Comp(NULL), Output(NULL)
{
if (File.empty() == true)
return;
@@ -568,10 +579,8 @@ bool TranslationWriter::DoPackage(string const &Pkg, string const &Desc,
/* */
TranslationWriter::~TranslationWriter()
{
if (Comp == NULL)
return;

delete Comp;
if (Comp != NULL)
delete Comp;
}
/*}}}*/



+ 5
- 9
ftparchive/writer.h View File

@@ -64,6 +64,7 @@ class FTWScanner

public:
FileFd *Output;
bool OwnsOutput;
unsigned int DoHashes;

unsigned long DeLinkLimit;
@@ -79,7 +80,7 @@ class FTWScanner
bool SetExts(string const &Vals);

FTWScanner(FileFd * const Output, string const &Arch = string());
virtual ~FTWScanner() {};
virtual ~FTWScanner();
};

class MultiCompress;
@@ -88,17 +89,12 @@ class TranslationWriter
{
MultiCompress *Comp;
std::set<string> Included;
unsigned short RefCounter;
FileFd *Output;

public:
void IncreaseRefCounter() { ++RefCounter; };
unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
unsigned short GetRefCounter() const { return RefCounter; };
bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);

TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
TranslationWriter() : Comp(NULL), RefCounter(0) {};
~TranslationWriter();
};

@@ -119,18 +115,18 @@ class PackagesWriter : public FTWScanner
string PathPrefix;
string DirStrip;
struct CacheDB::Stats &Stats;
TranslationWriter *TransWriter;
TranslationWriter * const TransWriter;

inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
inline bool ReadExtraOverride(string const &File)
{return Over.ReadExtraOverride(File);};
virtual bool DoPackage(string FileName);

PackagesWriter(FileFd * const Output, string const &DB,
PackagesWriter(FileFd * const Output, TranslationWriter * const TransWriter, string const &DB,
string const &Overrides,
string const &ExtOverrides = "",
string const &Arch = "");
virtual ~PackagesWriter() {};
virtual ~PackagesWriter();
};

class ContentsWriter : public FTWScanner


+ 3
- 0
test/integration/framework View File

@@ -143,6 +143,7 @@ gdb() {
aptcache) CMD="apt-cache";;
aptmark) CMD="apt-mark";;
apthelper) CMD="apt-helper";;
aptftparchive) CMD="apt-ftparchive";;
*) CMD="$1";;
esac
shift
@@ -1415,6 +1416,8 @@ testfailure() {
if expr match "$1" '^apt.*' >/dev/null; then
if grep -q -E ' runtime error: ' "$OUTPUT"; then
msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
elif grep -q -E '==ERROR' "$OUTPUT"; then
msgfailoutput 'compiler sanitizers reported errors' "$OUTPUT" "$@"
elif ! grep -q -E '^E: ' "$OUTPUT"; then
msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
else


+ 3
- 4
test/libapt/cdrom_test.cc View File

@@ -91,7 +91,7 @@ TEST(CDROMTest,ReduceSourcelist)
}
TEST(CDROMTest, FindMountPointForDevice)
{
char * tempfile = NULL;
std::string tempfile;
FileFd fd;
createTemporaryFile("mountpoints", fd, &tempfile,
"rootfs / rootfs rw 0 0\n"
@@ -109,7 +109,6 @@ TEST(CDROMTest, FindMountPointForDevice)
EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1"));
EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs"));

if (tempfile != NULL)
unlink(tempfile);
free(tempfile);
if (tempfile.empty() == false)
unlink(tempfile.c_str());
}

+ 3
- 4
test/libapt/file-helpers.cc View File

@@ -53,20 +53,19 @@ void helperCreateLink(std::string const &dir, std::string const &targetname, std
link.append(linkname);
ASSERT_EQ(0, symlink(target.c_str(), link.c_str()));
}
void helperCreateTemporaryFile(std::string const &id, FileFd &fd, char * * const filename, char const * const content)
void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content)
{
std::string name("apt-test-");
name.append(id).append(".XXXXXXXX");
char * tempfile = strdup(name.c_str());
ASSERT_STRNE(NULL, tempfile);
int tempfile_fd = mkstemp(tempfile);
ASSERT_NE(-1, tempfile_fd);
if (filename != NULL)
*filename = tempfile;
else
{
unlink(tempfile);
free(tempfile);
}
free(tempfile);

EXPECT_TRUE(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite));
if (content != NULL)


+ 1
- 1
test/libapt/file-helpers.h View File

@@ -24,6 +24,6 @@ void helperCreateDirectory(std::string const &dir, std::string const &name);
void helperCreateLink(std::string const &dir, std::string const &targetname, std::string const &linkname);
#define createTemporaryFile(id, fd, filename, content) \
ASSERT_NO_FATAL_FAILURE(helperCreateTemporaryFile(id, fd, filename, content))
void helperCreateTemporaryFile(std::string const &id, FileFd &fd, char * * const filename, char const * const content);
void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content);

#endif

+ 3
- 2
test/libapt/sourcelist_test.cc View File

@@ -20,7 +20,7 @@ class SourceList : public pkgSourceList {
TEST(SourceListTest,ParseFileDeb822)
{
FileFd fd;
char * tempfile = NULL;
std::string tempfile;
createTemporaryFile("parsefiledeb822", fd, &tempfile,
"Types: deb\n"
"URIs: http://ftp.debian.org/debian\n"
@@ -39,5 +39,6 @@ TEST(SourceListTest,ParseFileDeb822)
EXPECT_EQ(2, sources.ParseFileDeb822(tempfile));
EXPECT_EQ(2, sources.size());

unlink(tempfile);
if (tempfile.empty() == false)
unlink(tempfile.c_str());
}

Loading…
Cancel
Save